Fix rss
Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
parent
68ba3502c7
commit
fb895092e8
7 changed files with 37 additions and 87 deletions
1
.github/FUNDING.yml
vendored
1
.github/FUNDING.yml
vendored
|
@ -1 +0,0 @@
|
||||||
github: kaivanwong
|
|
27
.github/workflows/ci.yml
vendored
27
.github/workflows/ci.yml
vendored
|
@ -1,27 +0,0 @@
|
||||||
name: CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
lint:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Set node
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: lts/*
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: npm install
|
|
||||||
|
|
||||||
- name: Lint
|
|
||||||
run: npm run lint
|
|
24
.github/workflows/release.yml
vendored
24
.github/workflows/release.yml
vendored
|
@ -1,24 +0,0 @@
|
||||||
name: Release
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- 'v*'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
release:
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: lts/*
|
|
||||||
|
|
||||||
- run: npx changelogiter
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
|
|
@ -5,7 +5,7 @@ import UnoCSS from 'unocss/astro'
|
||||||
import vue from '@astrojs/vue'
|
import vue from '@astrojs/vue'
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
site: 'https://astro-theme-vitesse.netlify.app/',
|
site: 'https://baalajimaestro.ptr.moe',
|
||||||
server: {
|
server: {
|
||||||
port: 1977,
|
port: 1977,
|
||||||
},
|
},
|
||||||
|
|
|
@ -40,9 +40,9 @@
|
||||||
"simple-git-hooks": "^2.11.1"
|
"simple-git-hooks": "^2.11.1"
|
||||||
},
|
},
|
||||||
"simple-git-hooks": {
|
"simple-git-hooks": {
|
||||||
"pre-commit": "npx lint-staged"
|
"pre-commit": "pnpm lint-staged"
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"*": "npm run lint:fix"
|
"*": "pnpm lint:fix"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +1,40 @@
|
||||||
import rss from '@astrojs/rss'
|
import rss from '@astrojs/rss';
|
||||||
import siteConfig from '@/site-config'
|
import siteConfig from '@/site-config';
|
||||||
import { getPosts } from '@/utils/posts'
|
import { api } from '@/utils/ghost'
|
||||||
|
|
||||||
interface Context {
|
interface Context {
|
||||||
site: string
|
site: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to strip HTML tags
|
||||||
|
function stripHtml(html: string) {
|
||||||
|
return html.replace(/<\/?[^>]+(>|$)/g, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function GET(context: Context) {
|
export async function GET(context: Context) {
|
||||||
const posts = await getPosts()
|
try {
|
||||||
|
// Fetch posts from Ghost
|
||||||
|
const posts = await api.posts.browse({
|
||||||
|
limit: 'all',
|
||||||
|
include: ['tags', 'authors'],
|
||||||
|
fields: ['id', 'title', 'slug', 'published_at', 'custom_excerpt', 'html']
|
||||||
|
});
|
||||||
|
|
||||||
return rss({
|
return rss({
|
||||||
title: siteConfig.title,
|
title: siteConfig.title,
|
||||||
description: siteConfig.description,
|
description: siteConfig.description,
|
||||||
site: context.site,
|
site: context.site,
|
||||||
items: posts!.map((item) => {
|
items: posts.map((post) => ({
|
||||||
return {
|
title: post.title,
|
||||||
...item.data,
|
description: post.custom_excerpt ? stripHtml(post.custom_excerpt) : '',
|
||||||
link: `${context.site}/posts/${item.slug}/`,
|
link: `${context.site}posts/${post.slug}/`,
|
||||||
pubDate: new Date(item.data.date),
|
pubDate: new Date(post.published_at),
|
||||||
content: item.body,
|
content: stripHtml(post.html),
|
||||||
author: `${siteConfig.author} <${siteConfig.email}>`,
|
author: post.primary_author ? post.primary_author.name : siteConfig.author,
|
||||||
}
|
})),
|
||||||
}),
|
});
|
||||||
})
|
} catch (error) {
|
||||||
}
|
console.error('Error generating RSS feed:', error);
|
||||||
|
return new Response('Error generating RSS feed', { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,12 +0,0 @@
|
||||||
import { getCollection } from 'astro:content'
|
|
||||||
import type { CollectionPosts, PostKey } from '@/types'
|
|
||||||
|
|
||||||
export function sortPostsByDate(itemA: CollectionPosts, itemB: CollectionPosts) {
|
|
||||||
return new Date(itemB.data.date).getTime() - new Date(itemA.data.date).getTime()
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getPosts(path?: string, collection: PostKey = 'blog') {
|
|
||||||
return (await getCollection(collection, (post) => {
|
|
||||||
return (import.meta.env.PROD ? post.data.draft !== true : true) && (path ? post.slug.includes(path) : true)
|
|
||||||
})).sort(sortPostsByDate)
|
|
||||||
}
|
|
Loading…
Reference in a new issue