Fix roadmap resource title escaping (#10037)
Co-authored-by: StaryMoon <minghao13187@gmail.com>
This commit is contained in:
1 parent
f4811e291f
commit
794a04484e
2 files changed
+29
-3
No files matched your search
@@ -3,7 +3,10 @@ import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { slugify } from '../src/lib/slugger';
|
||||
import type { OfficialRoadmapDocument } from '../src/queries/official-roadmap';
|
||||
import type { OfficialRoadmapTopicContentDocument } from '../src/queries/official-roadmap-topic';
|
||||
import {
|
||||
formatOfficialRoadmapTopicResourceLink,
|
||||
type OfficialRoadmapTopicContentDocument,
|
||||
} from '../src/queries/official-roadmap-topic';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
@@ -106,7 +109,11 @@ function prepareTopicContent(topic: OfficialRoadmapTopicContentDocument) {
|
||||
|
||||
let content = description;
|
||||
if (resources.length > 0) {
|
||||
content += `\n\nVisit the following resources to learn more:\n\n${resources.map((resource) => `- [@${resource.type}@${resource.title}](${resource.url})`).join('\n')}`;
|
||||
const resourceLinks = resources
|
||||
.map(formatOfficialRoadmapTopicResourceLink)
|
||||
.join('\n');
|
||||
|
||||
content += `\n\nVisit the following resources to learn more:\n\n${resourceLinks}`;
|
||||
}
|
||||
|
||||
return content;
|
||||
|
||||
@@ -63,6 +63,21 @@ export async function getOfficialRoadmapTopic(
|
||||
}
|
||||
}
|
||||
|
||||
export function escapeMarkdownLinkText(text: string) {
|
||||
return text
|
||||
.replace(/\\/g, '\\\\')
|
||||
.replace(/</g, '\\<')
|
||||
.replace(/>/g, '\\>')
|
||||
.replace(/\[/g, '\\[')
|
||||
.replace(/\]/g, '\\]');
|
||||
}
|
||||
|
||||
export function formatOfficialRoadmapTopicResourceLink(
|
||||
resource: Pick<OfficialRoadmapTopicResource, 'type' | 'title' | 'url'>,
|
||||
) {
|
||||
return `- [@${resource.type}@${escapeMarkdownLinkText(resource.title)}](${resource.url})`;
|
||||
}
|
||||
|
||||
export function prepareOfficialRoadmapTopicContent(
|
||||
topic: OfficialRoadmapTopicContentDocument,
|
||||
) {
|
||||
@@ -70,7 +85,11 @@ export function prepareOfficialRoadmapTopicContent(
|
||||
|
||||
let content = description;
|
||||
if (resources.length > 0) {
|
||||
content += `\n\nVisit the following resources to learn more:\n\n${resources.map((resource) => `- [@${resource.type}@${resource.title}](${resource.url})`).join('\n')}`;
|
||||
const resourceLinks = resources
|
||||
.map(formatOfficialRoadmapTopicResourceLink)
|
||||
.join('\n');
|
||||
|
||||
content += `\n\nVisit the following resources to learn more:\n\n${resourceLinks}`;
|
||||
}
|
||||
|
||||
return content;
|
||||
|
||||
Reference in new issue
Block a user