Skip to content

Commit 408ab77

Browse files
authored
feat: OnThisPage blog (#9216)
* 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` * Bump site-kit * Add content
1 parent 8e85b3f commit 408ab77

File tree

6 files changed

+40
-20
lines changed

6 files changed

+40
-20
lines changed

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sites/svelte.dev/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"@resvg/resvg-js": "^2.4.1",
3131
"@sveltejs/adapter-vercel": "^3.0.3",
3232
"@sveltejs/kit": "^1.24.1",
33-
"@sveltejs/site-kit": "6.0.0-next.45",
33+
"@sveltejs/site-kit": "6.0.0-next.46",
3434
"@sveltejs/vite-plugin-svelte": "^2.4.6",
3535
"@types/cookie": "^0.5.2",
3636
"@types/node": "^20.5.9",

sites/svelte.dev/src/lib/server/blog/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { extractFrontmatter } from '@sveltejs/site-kit/markdown';
33
import { CONTENT_BASE_PATHS } from '../../../constants.js';
44
import { render_content } from '../renderer.js';
5+
import { get_sections } from '../docs/index.js';
56

67
/**
78
* @param {import('./types').BlogData} blog_data
@@ -47,7 +48,8 @@ export async function get_blog_data(base = CONTENT_BASE_PATHS.BLOG) {
4748
author: {
4849
name: metadata.author,
4950
url: metadata.authorURL
50-
}
51+
},
52+
sections: await get_sections(body)
5153
});
5254
}
5355

sites/svelte.dev/src/lib/server/blog/types.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { Section } from '../docs/types';
2+
13
export interface BlogPost {
24
title: string;
35
description: string;
@@ -11,6 +13,7 @@ export interface BlogPost {
1113
};
1214
draft: boolean;
1315
content: string;
16+
sections: Section[];
1417
}
1518

1619
export type BlogData = BlogPost[];

sites/svelte.dev/src/lib/server/docs/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,12 @@ const titled = async (str) =>
107107
.replace(/"/g, '"')
108108
.replace(/&lt;/g, '<')
109109
.replace(/&gt;/g, '>')
110+
.replace(/&amp;/, '&')
110111
.replace(/<(\/)?(em|b|strong|code)>/g, '')
111112
);
112113

113114
/** @param {string} markdown */
114-
async function get_sections(markdown) {
115+
export async function get_sections(markdown) {
115116
const lines = markdown.split('\n');
116117
const root = /** @type {import('./types').Section} */ ({
117118
title: 'Root',

sites/svelte.dev/src/routes/blog/[slug]/+page.svelte

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script>
22
import { page } from '$app/stores';
33
import { copy_code_descendants } from '@sveltejs/site-kit/actions';
4-
import { setupDocsHovers } from '@sveltejs/site-kit/docs';
4+
import { DocsOnThisPage, setupDocsHovers } from '@sveltejs/site-kit/docs';
55
66
export let data;
77
@@ -20,17 +20,31 @@
2020
<meta name="og:image" content="https://svelte.dev/blog/{$page.params.slug}/card.png" />
2121
</svelte:head>
2222

23-
<article class="post listify text" use:copy_code_descendants>
24-
<h1>{data.post.title}</h1>
25-
<p class="standfirst">{data.post.description}</p>
26-
27-
<p class="byline">
28-
<a href={data.post.author.url}>{data.post.author.name}</a>
29-
<time datetime={data.post.date}>{data.post.date_formatted}</time>
30-
</p>
31-
32-
{@html data.post.content}
33-
</article>
23+
<div class="content">
24+
<article class="post listify text" use:copy_code_descendants>
25+
<h1>{data.post.title}</h1>
26+
<p class="standfirst">{data.post.description}</p>
27+
28+
<p class="byline">
29+
<a href={data.post.author.url}>{data.post.author.name}</a>
30+
<time datetime={data.post.date}>{data.post.date_formatted}</time>
31+
</p>
32+
33+
<DocsOnThisPage
34+
details={{
35+
content: '',
36+
file: '',
37+
path: `/blog/${data.post.slug}`,
38+
sections: data.post.sections,
39+
slug: data.post.slug,
40+
title: data.post.title
41+
}}
42+
orientation="inline"
43+
/>
44+
45+
{@html data.post.content}
46+
</article>
47+
</div>
3448

3549
<!-- the crawler doesn't understand twitter:image etc, so we have to add this hack. TODO fix in sveltekit -->
3650
<img hidden src="/blog/{$page.params.slug}/card.png" alt="Social card for {data.post.title}" />
@@ -54,7 +68,7 @@
5468
}
5569
5670
.byline {
57-
margin: 0 0 6rem 0;
71+
margin: 0 0 1rem 0;
5872
padding: 1.6rem 0 0 0;
5973
border-top: var(--sk-thick-border-width) solid #6767785b;
6074
font-size: var(--sk-text-xs);

0 commit comments

Comments
 (0)