You've already forked joplin
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:
@ -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() {
|
||||||
|
@ -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) => {
|
||||||
|
@ -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) {
|
||||||
|
Reference in New Issue
Block a user