Initial commit

Static site generation from md wip
This commit is contained in:
2023-09-15 22:35:15 +02:00
commit 24fd81c32c
11 changed files with 1213 additions and 0 deletions

5
.firebaserc Normal file
View File

@@ -0,0 +1,5 @@
{
"projects": {
"default": "blog-zacke-dev"
}
}

68
.gitignore vendored Normal file
View File

@@ -0,0 +1,68 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
firebase-debug.log*
firebase-debug.*.log*
# Firebase cache
.firebase/
# Firebase config
# Uncomment this if you'd like others to create their own Firebase project.
# For a team working on the same Firebase project(s), it is recommended to leave
# it commented so all members can deploy to the same project(s) in .firebaserc.
# .firebaserc
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.dist

69
build.js Normal file
View File

@@ -0,0 +1,69 @@
import * as fs from "fs";
const paths = {
output: ".dist",
notes: {
root: "notes",
assets: "assets",
note: "note.md",
},
templates: {
root: "templates",
note: "note.html",
index: "index.html",
notFound: "404.html",
},
};
if (fs.readdirSync(".").includes(paths.output)) {
fs.rmSync(paths.output, { recursive: true, force: true });
}
fs.mkdirSync(paths.output);
const directoryNames = fs.readdirSync(paths.notes.root);
const manifest = directoryNames.map((noteDirectory) => ({
directoryName: noteDirectory,
name: noteDirectory,
markdown: fs.readFileSync(
`${paths.notes.root}/${noteDirectory}/${paths.notes.note}`,
{ encoding: "utf-8" }
),
assetDirectoryPath: `${paths.notes.root}/${noteDirectory}/${paths.notes.assets}`,
}));
manifest.forEach((m) => {
const notePath = `${paths.templates.root}/${paths.templates.note}`;
let htmlTemplate = fs.readFileSync(notePath, {
encoding: "utf-8",
});
htmlTemplate = htmlTemplate.replace("{{markdown}}", m.markdown);
fs.writeFileSync(`${paths.output}/${m.directoryName}.html`, htmlTemplate, {
encoding: "utf-8",
flag: "ax",
});
});
[paths.templates.notFound].forEach((filename) => {
fs.copyFileSync(
`${paths.templates.root}/${filename}`,
`${paths.output}/${filename}`
);
});
let htmlTemplate = fs.readFileSync(
`${paths.templates.root}/${paths.templates.index}`,
{
encoding: "utf-8",
}
);
const links = manifest.map(
(m) => `<a href='/${m.directoryName}.html'>${m.name}</a>`
);
htmlTemplate = htmlTemplate.replace("{{content}}", links);
fs.writeFileSync(`${paths.output}/index.html`, htmlTemplate, {
encoding: "utf-8",
flag: "ax",
});
console.log(manifest);

6
firebase.json Normal file
View File

@@ -0,0 +1,6 @@
{
"hosting": {
"public": ".dist",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"]
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@@ -0,0 +1,6 @@
# Initial commit
Testing
- testing
[testing](https://blog.zacke.dev)

1001
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

19
package.json Normal file
View File

@@ -0,0 +1,19 @@
{
"name": "blog",
"version": "1.0.0",
"description": "",
"type": "module",
"main": "index.js",
"scripts": {
"init": "npm install -g firebase-tools && firebase login",
"serve": "serve .dist"
},
"author": "",
"license": "ISC",
"devDependencies": {
"serve": "^14.2.1"
},
"dependencies": {
"@types/node": "^20.6.1"
}
}

17
templates/404.html Normal file
View File

@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Page Not Found</title>
</head>
<body>
<div id="message">
<h2>404</h2>
<h1>Page Not Found</h1>
<p>The specified file was not found on this website. Please check the URL for mistakes and try again.</p>
<h3>Why am I seeing this?</h3>
<p>This page was generated by the Firebase Command-Line Interface. To modify it, edit the <code>404.html</code> file in your project's configured <code>public</code> directory.</p>
</div>
</body>
</html>

11
templates/index.html Normal file
View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
{{content}}
</body>
</html>

11
templates/note.html Normal file
View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
{{markdown}}
</body>
</html>