Skip to content

Commit 0b659f8

Browse files
committed
docs: kube-rs blog post
1 parent 0c56ac0 commit 0b659f8

File tree

10 files changed

+422
-10
lines changed

10 files changed

+422
-10
lines changed

.github/workflows/build.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,16 @@ jobs:
9393
- name: tags
9494
run: git fetch --prune --unshallow --tags
9595

96+
- name: Install toolchain
97+
run: rustup show active-toolchain
98+
- uses: Swatinem/rust-cache@v2
99+
- uses: cargo-bins/cargo-binstall@main
96100
- uses: taiki-e/install-action@v2
97101
with:
98102
tool: git-cliff
99103
- uses: jdx/mise-action@v2
100104
with:
101105
experimental: true
102-
mise_toml: |
103-
[tools]
104-
helm = "latest"
105-
just = "latest"
106106

107107
- name: helm
108108
run: |

docs/app/layout.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export const metadata = {
2+
title: 'Next.js',
3+
description: 'Generated by Next.js',
4+
}
5+
6+
export default function RootLayout({
7+
children,
8+
}: {
9+
children: React.ReactNode
10+
}) {
11+
return (
12+
<html lang="en">
13+
<body>{children}</body>
14+
</html>
15+
)
16+
}

docs/app/rss.xml/route.ts

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import fs from 'node:fs/promises'
2+
import path from 'node:path'
3+
import { compileMdx } from 'nextra/compile'
4+
import { toString } from 'hast-util-to-string'
5+
import { type Root } from 'hast'
6+
import { type Plugin } from 'unified'
7+
import RSS from 'rss'
8+
9+
const SITE_URL = 'https://kty.dev'
10+
11+
const rehypeEnhanceFrontmatter: Plugin<[], Root> = () => (tree, file) => {
12+
const { frontMatter } = file.data as {
13+
frontMatter: Record<string, string | Date>
14+
}
15+
16+
tree = {
17+
...tree,
18+
children: tree.children.filter((node) => (node as any).tagName !== 'pre'),
19+
}
20+
21+
const [filePath] = file.history
22+
23+
frontMatter.description = toString(tree as any).trimStart()
24+
frontMatter.fileName = path.parse(filePath).name
25+
frontMatter.date = new Date(frontMatter.date)
26+
}
27+
28+
export async function GET() {
29+
const files = await fs.readdir('./pages/blog')
30+
31+
const blogs = await Promise.all(
32+
files
33+
.filter((filename) => /\.mdx?$/.test(filename))
34+
.map(async (filename) => {
35+
const filePath = path.join('./pages/blog', filename)
36+
const content = await fs.readFile(filePath, 'utf8')
37+
return await compileMdx(content, {
38+
filePath,
39+
mdxOptions: {
40+
rehypePlugins: [rehypeEnhanceFrontmatter],
41+
},
42+
})
43+
}),
44+
)
45+
46+
blogs.sort((a, b) => b.frontMatter.date - a.frontMatter.date)
47+
48+
const feed = new RSS({
49+
title: 'Blog',
50+
description: 'Blog',
51+
feed_url: `${SITE_URL}/rss.xml`,
52+
site_url: SITE_URL,
53+
language: 'en-US',
54+
pubDate: blogs[0].frontMatter.date.toUTCString(),
55+
ttl: 60,
56+
})
57+
58+
for (const { frontMatter } of blogs) {
59+
feed.item({
60+
title: frontMatter.title,
61+
description: frontMatter.description.slice(0, 139) + '…',
62+
url: `${SITE_URL}/blog/${frontMatter.fileName}`,
63+
author: frontMatter.byline,
64+
date: frontMatter.date.toUTCString(),
65+
})
66+
}
67+
68+
return new Response(feed.xml({ indent: true }), {
69+
headers: {
70+
'Content-Type': 'application/xml; charset=utf-8',
71+
},
72+
})
73+
}

docs/next-env.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3+
/// <reference types="next/navigation-types/compat/navigation" />
34

45
// NOTE: This file should not be edited
5-
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
6+
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.

docs/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"posthog-js": "^1.162.0",
3434
"react": "^18.3.1",
3535
"react-dom": "^18.3.1",
36-
"remark-frontmatter": "^5.0.0"
36+
"remark-frontmatter": "^5.0.0",
37+
"rss": "^1.2.2"
3738
},
3839
"devDependencies": {
3940
"@types/mdast": "^4.0.4",

0 commit comments

Comments
 (0)