pull/8435/head
Puru Vijay 3 years ago
parent 9ed6d09bf8
commit 302bae7839

@ -1,7 +1,13 @@
// @ts-check
import { base as app_base } from '$app/paths';
import fs from 'fs';
import { extract_frontmatter, normalizeSlugify, removeMarkdown, transform } from '../markdown';
import {
escape,
extract_frontmatter,
normalizeSlugify,
removeMarkdown,
transform
} from '../markdown';
const BASE = '../../site/content/docs/';
@ -79,11 +85,12 @@ function get_sections(markdown) {
while ((match = headingRegex.exec(markdown)) !== null) {
secondLevelHeadings.push({
title: removeMarkdown(
transform(match[1], { paragraph: (txt) => txt })
escape(transform(match[1], { paragraph: (txt) => txt }))
.replace(/<\/?code>/g, '')
.replace(/&quot;/g, '"')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/<(\/)?(em|b|strong|code)>/g, '')
),
slug: normalizeSlugify(match[1])
});

@ -51,12 +51,13 @@ export function slugify(title) {
/** @param {string} markdown */
export function removeMarkdown(markdown) {
return markdown
.replace(/\*\*(.+?)\*\*/g, '$1')
.replace(/\*(.+?)\*/g, '$1')
.replace(/`(.+?)`/g, '$1')
.replace(/~~(.+?)~~/g, '$1')
.replace(/\[(.+?)\]\(.+?\)/g, '$1')
.replace(/\n/g, ' ')
.replace(/\*\*(.+?)\*\*/g, '$1') // bold
.replace(/_(.+?)_/g, '$1') // Italics
.replace(/\*(.+?)\*/g, '$1') // Italics
.replace(/`(.+?)`/g, '$1') // Inline code
.replace(/~~(.+?)~~/g, '$1') // Strikethrough
.replace(/\[(.+?)\]\(.+?\)/g, '$1') // Link
.replace(/\n/g, ' ') // New line
.replace(/ {2,}/g, ' ')
.trim();
}

@ -46,7 +46,7 @@ export function content() {
const { body, metadata } = extract_frontmatter(markdown);
const sections = body.trim().split(/^### /m);
const sections = body.trim().split(/^## /m);
const intro = sections.shift().trim();
const rank = +metadata.rank || undefined;
@ -59,32 +59,32 @@ export function content() {
for (const section of sections) {
const lines = section.split('\n');
const h3 = lines.shift();
const h2 = lines.shift();
const content = lines.join('\n');
const subsections = content.trim().split('### ');
const subsections = content.trim().split('## ');
const intro = subsections.shift().trim();
blocks.push({
breadcrumbs: [...breadcrumbs, removeMarkdown(metadata.title), removeMarkdown(h3)],
href: category.href([slug, normalizeSlugify(h3)]),
breadcrumbs: [...breadcrumbs, removeMarkdown(metadata.title), removeMarkdown(h2)],
href: category.href([slug, normalizeSlugify(h2)]),
content: plaintext(intro),
rank
});
for (const subsection of subsections) {
const lines = subsection.split('\n');
const h4 = lines.shift();
const h3 = lines.shift();
blocks.push({
breadcrumbs: [
...breadcrumbs,
removeMarkdown(metadata.title),
removeMarkdown(h3),
removeMarkdown(h4)
removeMarkdown(h2),
removeMarkdown(h3)
],
href: category.href([slug, normalizeSlugify(h3), normalizeSlugify(h4)]),
href: category.href([slug, normalizeSlugify(h2), normalizeSlugify(h3)]),
content: plaintext(lines.join('\n').trim()),
rank
});

Loading…
Cancel
Save