Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
baalajimaestro 2024-07-14 10:46:33 +05:30
parent 68ba3502c7
commit fb895092e8
Signed by: baalajimaestro
GPG key ID: F93C394FE9BBAFD5
7 changed files with 37 additions and 87 deletions

1
.github/FUNDING.yml vendored
View file

@ -1 +0,0 @@
github: kaivanwong

View file

@ -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

View file

@ -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}}

View file

@ -5,7 +5,7 @@ import UnoCSS from 'unocss/astro'
import vue from '@astrojs/vue'
export default defineConfig({
site: 'https://astro-theme-vitesse.netlify.app/',
site: 'https://baalajimaestro.ptr.moe',
server: {
port: 1977,
},

View file

@ -40,9 +40,9 @@
"simple-git-hooks": "^2.11.1"
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
"pre-commit": "pnpm lint-staged"
},
"lint-staged": {
"*": "npm run lint:fix"
"*": "pnpm lint:fix"
}
}

View file

@ -1,26 +1,40 @@
import rss from '@astrojs/rss'
import siteConfig from '@/site-config'
import { getPosts } from '@/utils/posts'
import rss from '@astrojs/rss';
import siteConfig from '@/site-config';
import { api } from '@/utils/ghost'
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) {
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({
title: siteConfig.title,
description: siteConfig.description,
site: context.site,
items: posts!.map((item) => {
return {
...item.data,
link: `${context.site}/posts/${item.slug}/`,
pubDate: new Date(item.data.date),
content: item.body,
author: `${siteConfig.author} <${siteConfig.email}>`,
items: posts.map((post) => ({
title: post.title,
description: post.custom_excerpt ? stripHtml(post.custom_excerpt) : '',
link: `${context.site}posts/${post.slug}/`,
pubDate: new Date(post.published_at),
content: stripHtml(post.html),
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 });
}
}),
})
}

View file

@ -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)
}