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:
parent
94dc216add
commit
252f08e828
@ -65,11 +65,6 @@ https://github.com/laurent22/joplin/blob/dev/{{{sourceMarkdownFile}}}
|
|||||||
{{{contentHtml}}}
|
{{{contentHtml}}}
|
||||||
{{#showBottomLinks}}
|
{{#showBottomLinks}}
|
||||||
<div class="bottom-links">
|
<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}}
|
{{#showImproveThisDoc}}
|
||||||
<a class="bottom-link" href="https://github.com/laurent22/joplin/blob/dev/{{{sourceMarkdownFile}}}">
|
<a class="bottom-link" href="https://github.com/laurent22/joplin/blob/dev/{{{sourceMarkdownFile}}}">
|
||||||
<i class="fab fa-github"></i> Improve this doc
|
<i class="fab fa-github"></i> Improve this doc
|
||||||
|
@ -111,7 +111,7 @@ function renderPageToHtml(md: string, targetPath: string, templateParams: Templa
|
|||||||
...templateParams,
|
...templateParams,
|
||||||
};
|
};
|
||||||
|
|
||||||
templateParams.showBottomLinks = templateParams.showImproveThisDoc || !!templateParams.discussOnForumLink;
|
templateParams.showBottomLinks = templateParams.showImproveThisDoc;
|
||||||
|
|
||||||
const title = [];
|
const title = [];
|
||||||
|
|
||||||
@ -139,6 +139,9 @@ function renderPageToHtml(md: string, targetPath: string, templateParams: Templa
|
|||||||
|
|
||||||
function renderFileToHtml(sourcePath: string, targetPath: string, templateParams: TemplateParams) {
|
function renderFileToHtml(sourcePath: string, targetPath: string, templateParams: TemplateParams) {
|
||||||
let md = readFileSync(sourcePath, 'utf8');
|
let md = readFileSync(sourcePath, 'utf8');
|
||||||
|
if (templateParams.isNews) {
|
||||||
|
md = processNewsMarkdown(md, sourcePath);
|
||||||
|
}
|
||||||
md = stripOffFrontMatter(md).doc;
|
md = stripOffFrontMatter(md).doc;
|
||||||
return renderPageToHtml(md, targetPath, templateParams);
|
return renderPageToHtml(md, targetPath, templateParams);
|
||||||
}
|
}
|
||||||
@ -168,6 +171,15 @@ async function loadSponsors(): Promise<Sponsors> {
|
|||||||
return output;
|
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 makeNewsFrontPage = async (sourceFilePaths: string[], targetFilePath: string, templateParams: TemplateParams) => {
|
||||||
const maxNewsPerPage = 20;
|
const maxNewsPerPage = 20;
|
||||||
|
|
||||||
@ -175,11 +187,7 @@ const makeNewsFrontPage = async (sourceFilePaths: string[], targetFilePath: stri
|
|||||||
|
|
||||||
for (const mdFilePath of sourceFilePaths) {
|
for (const mdFilePath of sourceFilePaths) {
|
||||||
let md = await readFile(mdFilePath, 'utf8');
|
let md = await readFile(mdFilePath, 'utf8');
|
||||||
const info = stripOffFrontMatter(md);
|
md = processNewsMarkdown(md, mdFilePath);
|
||||||
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})`;
|
|
||||||
frontPageMd.push(md);
|
frontPageMd.push(md);
|
||||||
if (frontPageMd.length >= maxNewsPerPage) break;
|
if (frontPageMd.length >= maxNewsPerPage) break;
|
||||||
}
|
}
|
||||||
@ -344,8 +352,8 @@ async function main() {
|
|||||||
...source[2],
|
...source[2],
|
||||||
templateHtml: mainTemplateHtml,
|
templateHtml: mainTemplateHtml,
|
||||||
pageName: isNews ? 'news-item' : '',
|
pageName: isNews ? 'news-item' : '',
|
||||||
discussOnForumLink: isNews ? discussLink : '',
|
|
||||||
showImproveThisDoc: !isNews,
|
showImproveThisDoc: !isNews,
|
||||||
|
isNews,
|
||||||
partials,
|
partials,
|
||||||
assetUrls,
|
assetUrls,
|
||||||
});
|
});
|
||||||
|
@ -71,9 +71,9 @@ export interface TemplateParams {
|
|||||||
navbar?: NavBar;
|
navbar?: NavBar;
|
||||||
showJoplinCloudLinks?: boolean;
|
showJoplinCloudLinks?: boolean;
|
||||||
assetUrls: AssetUrls;
|
assetUrls: AssetUrls;
|
||||||
discussOnForumLink?: string;
|
|
||||||
showBottomLinks?: boolean;
|
showBottomLinks?: boolean;
|
||||||
openGraph: OpenGraphTags;
|
openGraph: OpenGraphTags;
|
||||||
|
isNews?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PlanPageParams extends TemplateParams {
|
export interface PlanPageParams extends TemplateParams {
|
||||||
|
Loading…
Reference in New Issue
Block a user