Doc: Add Twitter and other metadata tags

pull/9166/head
Laurent Cozic 2023-10-30 12:57:56 +00:00
parent 0915ef768e
commit 467730b689
3 changed files with 11 additions and 3 deletions

View File

@ -12,6 +12,7 @@ import markdownUtils, { MarkdownTable } from '@joplin/lib/markdownUtils';
import { readmeFileTitle } from './utils/parser';
import { chdir } from 'process';
import yargs = require('yargs');
import { extractOpenGraphTags } from './utils/openGraph';
const md5File = require('md5-file');
const htmlparser2 = require('@joplin/fork-htmlparser2');
@ -370,10 +371,14 @@ const processMarkdownFile = async (sourcePath: string, destPath: string, context
mdAndFrontMatter.header.date = formatted;
}
const og = await extractOpenGraphTags(sourcePath);
mdAndFrontMatter.header.title = og.title;
mdAndFrontMatter.header.description = og.description;
if (og.image) mdAndFrontMatter.header.image = og.image;
mdAndFrontMatter.doc = mdAndFrontMatter.doc.replace(/^# (.*)\n/, `# $1\n\n${context.donateLinks}\n\n`);
if (mdAndFrontMatter.header.forum_url) {
// mdAndFrontMatter.doc += `\n\n* * *\n\n[<i class="fab fa-discourse"></i> Discuss on the forum](${mdAndFrontMatter.header.forum_url})`;
mdAndFrontMatter.doc += `\n\n* * *\n\n[<icon icon="fa-brands fa-discourse" size="lg" /> Discuss on the forum](${mdAndFrontMatter.header.forum_url})`;
}

View File

@ -13,6 +13,9 @@ export interface FrontMatter {
sidebar_label?: string;
sidebar_position?: number;
date?: string;
title?: string;
description?: string;
image?: string;
}
export interface MarkdownAndFrontMatter {

View File

@ -28,13 +28,13 @@ const getImageUrl = (content: string): string | null => {
return imageUrl;
};
export const extractOpenGraphTags = async (sourcePath: string, url: string): Promise<OpenGraphTags> => {
export const extractOpenGraphTags = async (sourcePath: string, url?: string): Promise<OpenGraphTags> => {
const doc = await readmeFileTitleAndBody(sourcePath);
const output: OpenGraphTags = {
title: substrWithEllipsis(doc.title, 0, 70),
description: substrWithEllipsis(markupToHtml().stripMarkup(MarkupLanguage.Markdown, doc.body), 0, 200),
url,
url: url ? url : '',
};
const imageUrl = getImageUrl(doc.body);