2024-08-30 00:55:26 +00:00
|
|
|
import SSSG, { Plugin } from "sssg";
|
2024-08-02 01:27:06 +00:00
|
|
|
import Variables from "sssg/src/plugins/variables";
|
|
|
|
import Dev from "sssg/src/plugins/dev";
|
|
|
|
import TSCompiler from "sssg/src/plugins/ts-compiler";
|
2024-08-30 00:55:26 +00:00
|
|
|
import MarkdownMetadata, {
|
|
|
|
parseMetadata,
|
|
|
|
} from "sssg/src/plugins/markdown-metadata";
|
2024-08-02 01:27:06 +00:00
|
|
|
import MarkdownCompiler from "sssg/src/plugins/markdown-compiler";
|
2024-08-28 23:42:24 +00:00
|
|
|
import CompileTimeJS from "sssg/src/plugins/compile-time-js";
|
2024-08-30 00:55:26 +00:00
|
|
|
import ImageOptimization from "sssg/src/plugins/image-optimization";
|
2024-08-02 01:27:06 +00:00
|
|
|
|
2024-08-30 00:55:26 +00:00
|
|
|
import { $ } from "bun";
|
2024-08-29 20:16:35 +00:00
|
|
|
|
2024-08-02 01:27:06 +00:00
|
|
|
import * as path from "path";
|
|
|
|
import * as fs from "fs";
|
|
|
|
|
|
|
|
const sssg = new SSSG({
|
|
|
|
outputFolder: path.join(__dirname, "dist"),
|
|
|
|
inputFolder: path.join(__dirname, "website"),
|
|
|
|
});
|
|
|
|
|
2024-08-30 00:55:26 +00:00
|
|
|
const gitLogShell =
|
|
|
|
await $`git log --pretty=format:'commit=%H%nauthor=%aN <%aE>%ndate=%ad%nmessage=%s%n=========' -1`.quiet();
|
2024-08-29 20:16:35 +00:00
|
|
|
const gitLogOutput = gitLogShell.text("utf8");
|
|
|
|
const gitLog = JSON.stringify(parseMetadata(gitLogOutput));
|
2024-08-30 00:55:26 +00:00
|
|
|
const plugins: Plugin[] = [];
|
|
|
|
|
|
|
|
if (process.argv.includes("--dev")) {
|
|
|
|
plugins.push(new Dev(sssg));
|
|
|
|
} else {
|
|
|
|
plugins.push(new ImageOptimization());
|
|
|
|
}
|
2024-08-29 20:16:35 +00:00
|
|
|
|
2024-08-02 01:27:06 +00:00
|
|
|
await sssg.run({
|
2024-08-30 00:55:26 +00:00
|
|
|
plugins: plugins.concat([
|
2024-08-28 23:42:24 +00:00
|
|
|
new CompileTimeJS(),
|
2024-08-02 01:27:06 +00:00
|
|
|
new Variables(() => {
|
|
|
|
const variables: Record<string, string> = {
|
|
|
|
__BLOG_POSTS__: JSON.stringify(
|
|
|
|
fs.readdirSync("./website/blogs").map((z) => z.replace(".md", ""))
|
|
|
|
),
|
2024-08-30 00:55:26 +00:00
|
|
|
__GIT_LOG_OUTPUT__: gitLog,
|
2024-08-02 01:27:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (fs.existsSync("./website/templates")) {
|
|
|
|
for (const file of fs.readdirSync("./website/templates")) {
|
|
|
|
const id = file.toUpperCase().replace(".HTML", "");
|
|
|
|
variables["__TEMPLATE_" + id + "__"] = fs
|
|
|
|
.readFileSync(path.join("./website/templates", file))
|
|
|
|
.toString("utf8");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return variables;
|
|
|
|
}),
|
|
|
|
new TSCompiler(),
|
|
|
|
new MarkdownMetadata(),
|
|
|
|
new MarkdownCompiler(),
|
2024-08-30 00:55:26 +00:00
|
|
|
]),
|
2024-08-02 01:27:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
await sssg.build();
|