1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-03 23:50:33 +02:00

Tools: Improve error message when website building fails

This commit is contained in:
Laurent Cozic
2022-11-15 16:00:06 +00:00
parent 341c9029c4
commit 0cfa07b1b0
3 changed files with 43 additions and 28 deletions

View File

@ -144,12 +144,17 @@ function renderPageToHtml(md: string, targetPath: string, templateParams: Templa
} }
function renderFileToHtml(sourcePath: string, targetPath: string, templateParams: TemplateParams) { function renderFileToHtml(sourcePath: string, targetPath: string, templateParams: TemplateParams) {
try {
let md = readFileSync(sourcePath, 'utf8'); let md = readFileSync(sourcePath, 'utf8');
if (templateParams.isNews) { if (templateParams.isNews) {
md = processNewsMarkdown(md, sourcePath); md = processNewsMarkdown(md, sourcePath);
} }
md = stripOffFrontMatter(md).doc; md = stripOffFrontMatter(md).doc;
return renderPageToHtml(md, targetPath, templateParams); return renderPageToHtml(md, targetPath, templateParams);
} catch (error) {
error.message = `Could not render file: ${sourcePath}: ${error.message}`;
throw error;
}
} }
function makeHomePageMd() { function makeHomePageMd() {

View File

@ -73,6 +73,7 @@ const getPosts = async (newsDir: string): Promise<Post[]> => {
}; };
const getPostContent = async (post: Post): Promise<PostContent> => { const getPostContent = async (post: Post): Promise<PostContent> => {
try {
const raw = await readFile(post.path, 'utf8'); const raw = await readFile(post.path, 'utf8');
const parsed = stripOffFrontMatter(raw); const parsed = stripOffFrontMatter(raw);
const lines = parsed.doc.split('\n'); const lines = parsed.doc.split('\n');
@ -85,6 +86,10 @@ const getPostContent = async (post: Post): Promise<PostContent> => {
body: lines.join('\n').trim(), body: lines.join('\n').trim(),
parsed, parsed,
}; };
} catch (error) {
error.message = `Could not get post content: ${post.id}: ${post.path}: ${error.message}`;
throw error;
}
}; };
const execApi = async (method: HttpMethod, path: string, body: Record<string, string | number> = null) => { const execApi = async (method: HttpMethod, path: string, body: Record<string, string | number> = null) => {

View File

@ -7,12 +7,13 @@ interface ReadmeDoc {
} }
export async function readmeFileTitleAndBody(sourcePath: string): Promise<ReadmeDoc> { export async function readmeFileTitleAndBody(sourcePath: string): Promise<ReadmeDoc> {
try {
let md = await readFile(sourcePath, 'utf8'); let md = await readFile(sourcePath, 'utf8');
md = stripOffFrontMatter(md).doc.trim(); md = stripOffFrontMatter(md).doc.trim();
const r = md.match(/^# (.*)/); const r = md.match(/^# (.*)/);
if (!r) { if (!r) {
throw new Error(`Could not determine title for Markdown file: ${sourcePath}`); throw new Error('Could not determine title');
} else { } else {
const lines = md.split('\n'); const lines = md.split('\n');
lines.splice(0, 1); lines.splice(0, 1);
@ -21,6 +22,10 @@ export async function readmeFileTitleAndBody(sourcePath: string): Promise<Readme
body: lines.join('\n'), body: lines.join('\n'),
}; };
} }
} catch (error) {
error.message = `On ${sourcePath}: ${error.message}`;
throw error;
}
} }
export async function readmeFileTitle(sourcePath: string) { export async function readmeFileTitle(sourcePath: string) {