feat: OnThisPage blog

### Before submitting the PR, please make sure you do the following

- [ ] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
- [ ] Prefix your PR title with `feat:`, `fix:`, `chore:`, or `docs:`.
- [ ] This message body should clearly illustrate what problems it solves.
- [ ] Ideally, include a test that fails without this PR but passes with it.

### Tests and linting

- [ ] Run the tests with `pnpm test` and lint the project with `pnpm lint`
pull/9216/head
Puru 3 years ago
parent 16504d1f52
commit abb3530475

@ -2,6 +2,7 @@
import { extractFrontmatter } from '@sveltejs/site-kit/markdown'; import { extractFrontmatter } from '@sveltejs/site-kit/markdown';
import { CONTENT_BASE_PATHS } from '../../../constants.js'; import { CONTENT_BASE_PATHS } from '../../../constants.js';
import { render_content } from '../renderer.js'; import { render_content } from '../renderer.js';
import { get_sections } from '../docs/index.js';
/** /**
* @param {import('./types').BlogData} blog_data * @param {import('./types').BlogData} blog_data
@ -47,7 +48,8 @@ export async function get_blog_data(base = CONTENT_BASE_PATHS.BLOG) {
author: { author: {
name: metadata.author, name: metadata.author,
url: metadata.authorURL url: metadata.authorURL
} },
sections: await get_sections(body)
}); });
} }

@ -1,3 +1,5 @@
import type { Section } from '../docs/types';
export interface BlogPost { export interface BlogPost {
title: string; title: string;
description: string; description: string;
@ -11,6 +13,7 @@ export interface BlogPost {
}; };
draft: boolean; draft: boolean;
content: string; content: string;
sections: Section[];
} }
export type BlogData = BlogPost[]; export type BlogData = BlogPost[];

@ -107,11 +107,12 @@ const titled = async (str) =>
.replace(/"/g, '"') .replace(/"/g, '"')
.replace(/&lt;/g, '<') .replace(/&lt;/g, '<')
.replace(/&gt;/g, '>') .replace(/&gt;/g, '>')
.replace(/&amp;/, '&')
.replace(/<(\/)?(em|b|strong|code)>/g, '') .replace(/<(\/)?(em|b|strong|code)>/g, '')
); );
/** @param {string} markdown */ /** @param {string} markdown */
async function get_sections(markdown) { export async function get_sections(markdown) {
const lines = markdown.split('\n'); const lines = markdown.split('\n');
const root = /** @type {import('./types').Section} */ ({ const root = /** @type {import('./types').Section} */ ({
title: 'Root', title: 'Root',

@ -1,6 +1,6 @@
<script> <script>
import { page } from '$app/stores'; import { page } from '$app/stores';
import { setupDocsHovers } from '@sveltejs/site-kit/docs'; import { DocsOnThisPage, setupDocsHovers } from '@sveltejs/site-kit/docs';
export let data; export let data;
@ -28,6 +28,18 @@
<time datetime={data.post.date}>{data.post.date_formatted}</time> <time datetime={data.post.date}>{data.post.date_formatted}</time>
</p> </p>
<DocsOnThisPage
details={{
content: '',
file: '',
path: `/blog/${data.post.slug}`,
sections: data.post.sections,
slug: data.post.slug,
title: data.post.title
}}
orientation="inline"
/>
{@html data.post.content} {@html data.post.content}
</article> </article>
@ -53,7 +65,7 @@
} }
.byline { .byline {
margin: 0 0 6rem 0; margin: 0 0 1rem 0;
padding: 1.6rem 0 0 0; padding: 1.6rem 0 0 0;
border-top: var(--sk-thick-border-width) solid #6767785b; border-top: var(--sk-thick-border-width) solid #6767785b;
font-size: var(--sk-text-xs); font-size: var(--sk-text-xs);

Loading…
Cancel
Save