add TOC add better blog navigation and a new blog post
This commit is contained in:
16
server/plugins/read-time.ts
Normal file
16
server/plugins/read-time.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { visit } from 'unist-util-visit'
|
||||
|
||||
const wpm = 225
|
||||
|
||||
export default defineNitroPlugin((nitroApp) => {
|
||||
nitroApp.hooks.hook('content:file:afterParse', (file) => {
|
||||
if (file._id.endsWith('.md')) {
|
||||
let wordCount = 0
|
||||
visit(file.body, (n: any) => n.type === 'text', (node) => {
|
||||
wordCount += node.value.trim().split(/\s+/).length
|
||||
})
|
||||
|
||||
file.readTime = Math.ceil(wordCount / wpm)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -3,23 +3,23 @@ import { streamToPromise } from 'sitemap'
|
||||
import RSS from 'rss'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
// Fetch all documents
|
||||
const docs = await serverQueryContent(event).where({ _draft: false }).find()
|
||||
const feed = new RSS({
|
||||
title: 'Juls07',
|
||||
description: 'Juls07\'s blogs',
|
||||
link: 'https://juls07.dev/blogs'
|
||||
})
|
||||
|
||||
for (const doc of docs) {
|
||||
feed.item({
|
||||
title: doc.title,
|
||||
description: doc.description,
|
||||
url: `https://juls07.dev${doc._path}`,
|
||||
image_url: doc.image.src,
|
||||
date: doc.date
|
||||
// Fetch all documents
|
||||
const docs = await serverQueryContent(event).where({ _draft: false }).find()
|
||||
const feed = new RSS({
|
||||
title: 'Juls07',
|
||||
description: 'Juls07\'s blogs',
|
||||
link: 'https://juls07.dev/blogs'
|
||||
})
|
||||
}
|
||||
|
||||
return feed.xml({ indent: true })
|
||||
for (const doc of docs) {
|
||||
feed.item({
|
||||
title: doc.title,
|
||||
description: doc.description,
|
||||
url: `https://juls07.dev${doc._path}`,
|
||||
image_url: doc.image.src,
|
||||
date: doc.date
|
||||
})
|
||||
}
|
||||
|
||||
return feed.xml({ indent: true })
|
||||
})
|
||||
|
||||
@@ -2,19 +2,19 @@ import { serverQueryContent } from '#content/server'
|
||||
import { SitemapStream, streamToPromise } from 'sitemap'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
// Fetch all documents
|
||||
const docs = await serverQueryContent(event).where({ _draft: false }).find()
|
||||
const sitemap = new SitemapStream({
|
||||
hostname: 'https://juls07.dev'
|
||||
})
|
||||
|
||||
for (const doc of docs) {
|
||||
sitemap.write({
|
||||
url: doc._path,
|
||||
changefreq: 'monthly'
|
||||
// Fetch all documents
|
||||
const docs = await serverQueryContent(event).where({ _draft: false }).find()
|
||||
const sitemap = new SitemapStream({
|
||||
hostname: 'https://juls07.dev'
|
||||
})
|
||||
}
|
||||
sitemap.end()
|
||||
|
||||
return streamToPromise(sitemap)
|
||||
for (const doc of docs) {
|
||||
sitemap.write({
|
||||
url: doc._path,
|
||||
changefreq: 'monthly'
|
||||
})
|
||||
}
|
||||
sitemap.end()
|
||||
|
||||
return streamToPromise(sitemap)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user