Skip to content

Commit

Permalink
fix build script
Browse files Browse the repository at this point in the history
  • Loading branch information
aorcsik committed Jul 31, 2024
1 parent cec096c commit fe7b63f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/js/BlogPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class BlogPage
let markdownString = markdownContent.toString();

const titleMatch = markdownString.match(/## (.*)/);
if (!titleMatch) throw new Error("Invalid Blog Post - Missing title");
if (!titleMatch) throw new Error(`Invalid Blog Post (${markdownPath}) - Missing title`);
data.title = titleMatch[1].trim();
markdownString = markdownString.replace(titleMatch[0], "");

Expand All @@ -60,7 +60,7 @@ class BlogPage
}

const metaDataMatch = markdownString.match(/<!-- (\{.*?\}) -->/s);
if (!metaDataMatch) throw new Error("Invalid Blog Post - Missing meta data");
if (!metaDataMatch) throw new Error(`Invalid Blog Post (${markdownPath}) - Missing meta data`);
markdownString = markdownString.replace(metaDataMatch[0], '');
const metaData = JSON.parse(metaDataMatch[1]);
Object.keys(metaData).forEach(key => {
Expand Down
26 changes: 12 additions & 14 deletions src/js/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,22 @@ async function buildPages(configPath) {

const markdownPages = await getPages(config.markdownDir);
for (let markdownPage of markdownPages) {
try {

const pagePath = markdownPage.split("/");
let filename = pagePath.pop();
const directory = pagePath.join("/");
if (markdownPage.match(/\/README.md$/)) continue;

try {
const directory = markdownPage.split("/").slice(0, -1).join("/");
if (directory) {
const targetDirectory = `${config.webDir}/${directory}`;
await fs.promises.mkdir(targetDirectory, { recursive: true });
console.log("+", targetDirectory);

filename = `${directory}/${filename}`;
const result = await fs.promises.mkdir(targetDirectory, { recursive: true });
if (result) console.log("+", result);
}

if (directory == "blog") {
const templatePath = `${config.templateDir}/_blog_post.ejs`;
const blogPage = await BlogPage.fromFile(config, markdownPage);
const targetFile = `${config.webDir}/${filename.replace(/\.md$/, ".html")}`;
const content = await renderTemplate(`${config.templateDir}/_blog_post.ejs`, {context: {...context, ...blogPage, bundle: ['client']}});
const content = await renderTemplate(templatePath, {context: {...context, ...blogPage, bundle: ['client']}});

const targetFile = `${config.webDir}/${markdownPage.replace(/\.md$/, ".html")}`;
await writeFile(targetFile, content);
console.log("+", targetFile);
}
Expand All @@ -56,15 +54,15 @@ async function buildPages(configPath) {
const directory = page.split("/").slice(0, -1).join("/");
if (directory) {
const targetDirectory = `${config.webDir}/${directory}`;
await fs.promises.mkdir(targetDirectory, { recursive: true });
console.log("+", targetDirectory);
const result = console.log(await fs.promises.mkdir(targetDirectory, { recursive: true }));
if (result) console.log("+", result);
}

const templatePath = `${config.templateDir}/${page}`;
context.path = `/${page.replace(/\.ejs$/, ".html")}`;
const content = await renderTemplate(templatePath, {context: {...context, bundle: ["client"]}});

const targetFile = `${config.webDir}/${context.path}`;
const targetFile = `${config.webDir}${context.path}`;
await writeFile(targetFile, content);
console.log("+", targetFile);

Expand Down

0 comments on commit fe7b63f

Please sign in to comment.