mirror of
https://github.com/KazooTTT/kazoottt-blog.git
synced 2025-06-21 17:51:32 +08:00
fix: 修改rss生成逻辑,修改目录生成逻辑
This commit is contained in:
@ -54,6 +54,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tailwindcss/aspect-ratio": "^0.4.2",
|
"@tailwindcss/aspect-ratio": "^0.4.2",
|
||||||
"@tailwindcss/typography": "^0.5.10",
|
"@tailwindcss/typography": "^0.5.10",
|
||||||
|
"@types/markdown-it": "^14.1.2",
|
||||||
"@types/sanitize-html": "^2.13.0",
|
"@types/sanitize-html": "^2.13.0",
|
||||||
"@typescript-eslint/parser": "^7.1.1",
|
"@typescript-eslint/parser": "^7.1.1",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
|
11091
pnpm-lock.yaml
generated
11091
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -6,6 +6,16 @@ const path = require('path')
|
|||||||
const contentDir = path.join(__dirname, '../src/content/post')
|
const contentDir = path.join(__dirname, '../src/content/post')
|
||||||
const USE_FULL_PATH = true
|
const USE_FULL_PATH = true
|
||||||
|
|
||||||
|
function toCamelCase(str) {
|
||||||
|
return str
|
||||||
|
.split(' ')
|
||||||
|
.map((word, index) => {
|
||||||
|
if (index === 0) return word.toLowerCase()
|
||||||
|
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
|
||||||
|
})
|
||||||
|
.join('')
|
||||||
|
}
|
||||||
|
|
||||||
function processDirectory(dir) {
|
function processDirectory(dir) {
|
||||||
fs.readdirSync(dir).forEach((item) => {
|
fs.readdirSync(dir).forEach((item) => {
|
||||||
const itemPath = path.join(dir, item)
|
const itemPath = path.join(dir, item)
|
||||||
@ -25,11 +35,13 @@ function getCategoryFromPath(filePath) {
|
|||||||
|
|
||||||
if (pathParts.length > 1) {
|
if (pathParts.length > 1) {
|
||||||
if (USE_FULL_PATH) {
|
if (USE_FULL_PATH) {
|
||||||
// Join all directory parts except the filename
|
// Join all directory parts except the filename and convert to camelCase if contains spaces
|
||||||
return pathParts.slice(0, -1).join('-')
|
const category = pathParts.slice(0, -1).join('-')
|
||||||
|
return category.includes(' ') ? toCamelCase(category) : category
|
||||||
} else {
|
} else {
|
||||||
// Just use the first directory after "post"
|
// Just use the first directory after "post" and convert to camelCase if contains spaces
|
||||||
return pathParts[0]
|
const category = pathParts[0]
|
||||||
|
return category.includes(' ') ? toCamelCase(category) : category
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ NotionID-notionnext: 80f19b4c-d207-45a0-bbbb-39641a9dc330
|
|||||||
link-notionnext: >-
|
link-notionnext: >-
|
||||||
https://kazoottt.notion.site/Possible-Causes-and-Solutions-for-Focusee-Switching-System-Audio-to-Speaker-Playback-forcibly-80f19b4cd20745a0bbbb39641a9dc330
|
https://kazoottt.notion.site/Possible-Causes-and-Solutions-for-Focusee-Switching-System-Audio-to-Speaker-Playback-forcibly-80f19b4cd20745a0bbbb39641a9dc330
|
||||||
rinId: 39
|
rinId: 39
|
||||||
category: english writing
|
category: englishWriting
|
||||||
---
|
---
|
||||||
|
|
||||||
# Possible Causes and Solutions for Focusee Switching System Audio to Speaker Playback Forcibly
|
# Possible Causes and Solutions for Focusee Switching System Audio to Speaker Playback Forcibly
|
||||||
|
@ -12,7 +12,7 @@ tags:
|
|||||||
- Refund
|
- Refund
|
||||||
finished: true
|
finished: true
|
||||||
published: true
|
published: true
|
||||||
category: english writing
|
category: englishWriting
|
||||||
slug: focusee-macos-review-en
|
slug: focusee-macos-review-en
|
||||||
description: An analysis of Focusee's shortcomings on macOS, including severe color discrepancies, slow export speed, and sound card configuration conflicts, along with the author's refund experience.
|
description: An analysis of Focusee's shortcomings on macOS, including severe color discrepancies, slow export speed, and sound card configuration conflicts, along with the author's refund experience.
|
||||||
NotionID-notionnext: c692f30c-bcbc-48fd-9739-19e23a3e1e40
|
NotionID-notionnext: c692f30c-bcbc-48fd-9739-19e23a3e1e40
|
||||||
|
@ -18,7 +18,7 @@ description: >-
|
|||||||
NotionID-notionnext: 96e4d436-6fd9-4fec-865c-ac2d80b06be0
|
NotionID-notionnext: 96e4d436-6fd9-4fec-865c-ac2d80b06be0
|
||||||
link-notionnext: 'https://kazoottt.notion.site/open-graph-intro-96e4d4366fd94fec865cac2d80b06be0'
|
link-notionnext: 'https://kazoottt.notion.site/open-graph-intro-96e4d4366fd94fec865cac2d80b06be0'
|
||||||
rinId: 17
|
rinId: 17
|
||||||
category: english writing
|
category: englishWriting
|
||||||
---
|
---
|
||||||
|
|
||||||
``
|
``
|
||||||
|
@ -2,27 +2,12 @@ import { siteConfig } from '@/site-config'
|
|||||||
import rss from '@astrojs/rss'
|
import rss from '@astrojs/rss'
|
||||||
import type { APIContext } from 'astro'
|
import type { APIContext } from 'astro'
|
||||||
import sanitizeHtml from 'sanitize-html'
|
import sanitizeHtml from 'sanitize-html'
|
||||||
|
import MarkdownIt from 'markdown-it';
|
||||||
|
import { getSortedAllPostsAndDiaries } from 'src/utils/post';
|
||||||
|
|
||||||
// Define an interface for your markdown files
|
const parser = new MarkdownIt();
|
||||||
interface MarkdownPost {
|
|
||||||
frontmatter: {
|
|
||||||
title?: string
|
|
||||||
date: string
|
|
||||||
description?: string
|
|
||||||
category?: string
|
|
||||||
slug: string
|
|
||||||
author?: string
|
|
||||||
}
|
|
||||||
compiledContent?: () => string
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function GET(context: APIContext) {
|
export async function GET(context: APIContext) {
|
||||||
const postImportResult = import.meta.glob('../content/post/**/*.md', { eager: true })
|
const blog = await getSortedAllPostsAndDiaries()
|
||||||
const posts = Object.values(postImportResult) as MarkdownPost[]
|
|
||||||
const sortedPosts = posts.sort(
|
|
||||||
(a, b) => new Date(b.frontmatter.date).valueOf() - new Date(a.frontmatter.date).valueOf()
|
|
||||||
)
|
|
||||||
|
|
||||||
return rss({
|
return rss({
|
||||||
title: siteConfig.title,
|
title: siteConfig.title,
|
||||||
description: siteConfig.description,
|
description: siteConfig.description,
|
||||||
@ -31,22 +16,20 @@ export async function GET(context: APIContext) {
|
|||||||
<feedId>75113012474671104</feedId>
|
<feedId>75113012474671104</feedId>
|
||||||
<userId>62156866798228480</userId>
|
<userId>62156866798228480</userId>
|
||||||
</follow_challenge>`,
|
</follow_challenge>`,
|
||||||
items: sortedPosts.map((post) => {
|
items: blog.map((post) => {
|
||||||
const prefix = post.frontmatter.category?.startsWith('日记-20') ? '/diary/' : '/blog/'
|
const prefix = post?.data.category?.startsWith('日记-20') ? '/diary/' : '/blog/'
|
||||||
return {
|
return {
|
||||||
title: post.frontmatter.title?.replace(/[\x00-\x1F\x7F-\x9F]/g, '') ?? '',
|
title: post.data.title,
|
||||||
pubDate: new Date(post.frontmatter.date),
|
pubDate: new Date(post.data.date),
|
||||||
description: post.frontmatter.description?.replace(/[\x00-\x1F\x7F-\x9F]/g, '') ?? '',
|
description: post.data.description ?? '',
|
||||||
link: `${prefix}${post.frontmatter.slug}`,
|
link: `${prefix}${post.slug}`,
|
||||||
content: sanitizeHtml(post.compiledContent?.() ?? '', {
|
content: sanitizeHtml(parser.render(post.body), {
|
||||||
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img']),
|
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img']),
|
||||||
allowedAttributes: {
|
textFilter: function (text) {
|
||||||
...sanitizeHtml.defaults.allowedAttributes,
|
return text.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F\uFFF0-\uFFFF]/g, '')
|
||||||
img: ['src', 'alt']
|
}
|
||||||
},
|
|
||||||
textFilter: (text) => text.replace(/[\x00-\x1F\x7F-\x9F]/g, '')
|
|
||||||
}),
|
}),
|
||||||
author: post.frontmatter.author?.replace(/[\x00-\x1F\x7F-\x9F]/g, '')
|
author: siteConfig.author
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -22,6 +22,14 @@ export const getAllDiariesSorted = async (): Promise<CollectionEntry<'post'>[]>
|
|||||||
return sortMDByDate(await getAllDiaries())
|
return sortMDByDate(await getAllDiaries())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const getSortedAllPostsAndDiaries = async (): Promise<CollectionEntry<'post'>[]> => {
|
||||||
|
const posts = await getCollection('post', ({ data }: { data: CollectionEntry<'post'> }) => {
|
||||||
|
return !data.draft
|
||||||
|
})
|
||||||
|
return sortMDByDate(posts)
|
||||||
|
}
|
||||||
|
|
||||||
export function sortMDByDate(posts: Array<CollectionEntry<'post'>>): CollectionEntry<'post'>[] {
|
export function sortMDByDate(posts: Array<CollectionEntry<'post'>>): CollectionEntry<'post'>[] {
|
||||||
return posts.sort((a, b) => {
|
return posts.sort((a, b) => {
|
||||||
const aDate = new Date(a.data.date).valueOf()
|
const aDate = new Date(a.data.date).valueOf()
|
||||||
|
Reference in New Issue
Block a user