mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Tools: Improve error message when website building fails
This commit is contained in:
parent
341c9029c4
commit
0cfa07b1b0
@ -144,12 +144,17 @@ function renderPageToHtml(md: string, targetPath: string, templateParams: Templa
|
||||
}
|
||||
|
||||
function renderFileToHtml(sourcePath: string, targetPath: string, templateParams: TemplateParams) {
|
||||
let md = readFileSync(sourcePath, 'utf8');
|
||||
if (templateParams.isNews) {
|
||||
md = processNewsMarkdown(md, sourcePath);
|
||||
try {
|
||||
let md = readFileSync(sourcePath, 'utf8');
|
||||
if (templateParams.isNews) {
|
||||
md = processNewsMarkdown(md, sourcePath);
|
||||
}
|
||||
md = stripOffFrontMatter(md).doc;
|
||||
return renderPageToHtml(md, targetPath, templateParams);
|
||||
} catch (error) {
|
||||
error.message = `Could not render file: ${sourcePath}: ${error.message}`;
|
||||
throw error;
|
||||
}
|
||||
md = stripOffFrontMatter(md).doc;
|
||||
return renderPageToHtml(md, targetPath, templateParams);
|
||||
}
|
||||
|
||||
function makeHomePageMd() {
|
||||
|
@ -73,18 +73,23 @@ const getPosts = async (newsDir: string): Promise<Post[]> => {
|
||||
};
|
||||
|
||||
const getPostContent = async (post: Post): Promise<PostContent> => {
|
||||
const raw = await readFile(post.path, 'utf8');
|
||||
const parsed = stripOffFrontMatter(raw);
|
||||
const lines = parsed.doc.split('\n');
|
||||
const titleLine = lines[0];
|
||||
if (!titleLine.startsWith('# ')) throw new Error('Cannot extract title from post: no header detected');
|
||||
lines.splice(0, 1);
|
||||
try {
|
||||
const raw = await readFile(post.path, 'utf8');
|
||||
const parsed = stripOffFrontMatter(raw);
|
||||
const lines = parsed.doc.split('\n');
|
||||
const titleLine = lines[0];
|
||||
if (!titleLine.startsWith('# ')) throw new Error('Cannot extract title from post: no header detected');
|
||||
lines.splice(0, 1);
|
||||
|
||||
return {
|
||||
title: titleLine.substr(1).trim(),
|
||||
body: lines.join('\n').trim(),
|
||||
parsed,
|
||||
};
|
||||
return {
|
||||
title: titleLine.substr(1).trim(),
|
||||
body: lines.join('\n').trim(),
|
||||
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) => {
|
||||
|
@ -7,19 +7,24 @@ interface ReadmeDoc {
|
||||
}
|
||||
|
||||
export async function readmeFileTitleAndBody(sourcePath: string): Promise<ReadmeDoc> {
|
||||
let md = await readFile(sourcePath, 'utf8');
|
||||
md = stripOffFrontMatter(md).doc.trim();
|
||||
const r = md.match(/^# (.*)/);
|
||||
try {
|
||||
let md = await readFile(sourcePath, 'utf8');
|
||||
md = stripOffFrontMatter(md).doc.trim();
|
||||
const r = md.match(/^# (.*)/);
|
||||
|
||||
if (!r) {
|
||||
throw new Error(`Could not determine title for Markdown file: ${sourcePath}`);
|
||||
} else {
|
||||
const lines = md.split('\n');
|
||||
lines.splice(0, 1);
|
||||
return {
|
||||
title: r[1],
|
||||
body: lines.join('\n'),
|
||||
};
|
||||
if (!r) {
|
||||
throw new Error('Could not determine title');
|
||||
} else {
|
||||
const lines = md.split('\n');
|
||||
lines.splice(0, 1);
|
||||
return {
|
||||
title: r[1],
|
||||
body: lines.join('\n'),
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
error.message = `On ${sourcePath}: ${error.message}`;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user