-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
46 lines (33 loc) · 1.14 KB
/
Copy pathindex.js
File metadata and controls
46 lines (33 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Modules import
import fs from "fs";
import { Edge } from "edge.js";
import matter from "gray-matter";
import markdownit from "markdown-it";
// Variables / Constants
const projectsFolder = "./projects";
const renderFolder = "./public";
// Configuration
const edge = Edge.create();
edge.mount(new URL("./views", import.meta.url));
const md = markdownit();
// Setup render
fs.mkdirSync(renderFolder, { recursive: true });
fs.cpSync("./assets", renderFolder, { recursive: true });
// Projects
let projects = [];
const projectFiles = fs.readdirSync(projectsFolder, { encoding: "utf-8" });
for (const projectFile of projectFiles) {
const content = fs.readFileSync(`${projectsFolder}/${projectFile}`, { encoding: "utf-8" });
const parsedContent = matter(content);
const markdown = parsedContent.content;
const contentHtml = md.render(markdown);
const project = {};
project.html = contentHtml;
project.data = parsedContent.data;
projects.push(project);
}
// Render HTML file
const html = edge.renderSync("index", { projects });
fs.writeFileSync(`${renderFolder}/index.html`, html, { recursive: true });
// OUTPUT
console.log("WEBSITE GENERATED!");