1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-11 18:24:43 +02:00

Doc: Improved rendering of news items

This commit is contained in:
Laurent Cozic 2022-03-03 14:06:37 +00:00
parent 94dc216add
commit 252f08e828
3 changed files with 16 additions and 13 deletions

View File

@ -65,11 +65,6 @@ https://github.com/laurent22/joplin/blob/dev/{{{sourceMarkdownFile}}}
{{{contentHtml}}}
{{#showBottomLinks}}
<div class="bottom-links">
{{#discussOnForumLink}}
<a class="bottom-link" href="{{{discussOnForumLink}}}">
<i class="fab fa-discourse"></i></i> Discuss on the forum
</a>
{{/discussOnForumLink}}
{{#showImproveThisDoc}}
<a class="bottom-link" href="https://github.com/laurent22/joplin/blob/dev/{{{sourceMarkdownFile}}}">
<i class="fab fa-github"></i> Improve this doc

View File

@ -111,7 +111,7 @@ function renderPageToHtml(md: string, targetPath: string, templateParams: Templa
...templateParams,
};
templateParams.showBottomLinks = templateParams.showImproveThisDoc || !!templateParams.discussOnForumLink;
templateParams.showBottomLinks = templateParams.showImproveThisDoc;
const title = [];
@ -139,6 +139,9 @@ 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);
}
md = stripOffFrontMatter(md).doc;
return renderPageToHtml(md, targetPath, templateParams);
}
@ -168,6 +171,15 @@ async function loadSponsors(): Promise<Sponsors> {
return output;
}
const processNewsMarkdown = (md: string, mdFilePath: string): string => {
const info = stripOffFrontMatter(md);
md = info.doc.trim();
const dateString = moment(info.created).format('D MMM YYYY');
md = md.replace(/^# (.*)/, `# [$1](https://github.com/laurent22/joplin/blob/dev/readme/news/${path.basename(mdFilePath)})\n\n*Published on **${dateString}***\n\n`);
md += `\n\n* * *\n\n[<i class="fab fa-discourse"></i> Discuss on the forum](${discussLink})`;
return md;
};
const makeNewsFrontPage = async (sourceFilePaths: string[], targetFilePath: string, templateParams: TemplateParams) => {
const maxNewsPerPage = 20;
@ -175,11 +187,7 @@ const makeNewsFrontPage = async (sourceFilePaths: string[], targetFilePath: stri
for (const mdFilePath of sourceFilePaths) {
let md = await readFile(mdFilePath, 'utf8');
const info = stripOffFrontMatter(md);
md = info.doc.trim();
const dateString = moment(info.created).format('D MMM YYYY');
md = md.replace(/^# (.*)/, `# [$1](https://github.com/laurent22/joplin/blob/dev/readme/news/${path.basename(mdFilePath)})\n\n*Published on **${dateString}***\n\n`);
md += `\n\n* * *\n\n[<i class="fab fa-discourse"></i> Discuss on the forum](${discussLink})`;
md = processNewsMarkdown(md, mdFilePath);
frontPageMd.push(md);
if (frontPageMd.length >= maxNewsPerPage) break;
}
@ -344,8 +352,8 @@ async function main() {
...source[2],
templateHtml: mainTemplateHtml,
pageName: isNews ? 'news-item' : '',
discussOnForumLink: isNews ? discussLink : '',
showImproveThisDoc: !isNews,
isNews,
partials,
assetUrls,
});

View File

@ -71,9 +71,9 @@ export interface TemplateParams {
navbar?: NavBar;
showJoplinCloudLinks?: boolean;
assetUrls: AssetUrls;
discussOnForumLink?: string;
showBottomLinks?: boolean;
openGraph: OpenGraphTags;
isNews?: boolean;
}
export interface PlanPageParams extends TemplateParams {