Skip to content

Commit

Permalink
feat: add rss feed for news
Browse files Browse the repository at this point in the history
Signed-off-by: nurRiyad <[email protected]>
  • Loading branch information
nurRiyad authored and romangg committed Nov 8, 2024
1 parent 79c4401 commit ef163e6
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 3 deletions.
5 changes: 5 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export default defineNuxtConfig({
hooks: {
async 'nitro:config'(nitroConfig) { await setDownloadRedirects(nitroConfig) },
},
nitro: {
prerender: {
routes: ['/news/feed.xml'],
},
},
})

// Creates redirects for our official downloads. These are needed by GNOME Boxes and other software depending on libosinfo.
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
"@nuxtjs/color-mode": "^3.4.1",
"@nuxtjs/tailwindcss": "^6.12.0",
"@tailwindcss/typography": "^0.5.13",
"@types/rss": "^0.0.32",
"@vueuse/core": "^10.10.0",
"@vueuse/nuxt": "^10.10.0",
"daisyui": "^4.12.2",
"eslint": "^9.3.0",
"rss": "^1.2.2",
"vite-plugin-eslint2": "^4.4.0"
},
"pnpm": {
Expand Down
44 changes: 41 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions server/routes/news/feed.xml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import RSS from 'rss'
import { serverQueryContent } from '#content/server'

export default defineEventHandler(async (event) => {
const feed = new RSS({
title: 'Manjaro Linux Official',
description: 'This page provides an overview of Manjaro Linux, an open source operating system designed for ease of use. Learn about its features, installation, and support options. Get the most out of Manjaro Linux with the latest news, downloads, and tips from our helpful community',
site_url: 'https://manjaro.org',
feed_url: `https://manjaro.org/news/feed.xml`,
})

const contents = await serverQueryContent(event)
.sort({ date: -1 })
.where({ _partial: false })
.find()

const blogPosts = contents.filter(doc => doc?._path?.includes('/news'))
for (const doc of blogPosts) {
feed.item({
title: doc.title ?? '-',
url: `https://manjaro.org${doc._path}`,
date: doc.date,
description: doc.description,
enclosure: {
url: `https://manjaro.org${doc._path}/${doc.image}`,
type: 'image/jpeg',
},
})
}

const feedString = feed.xml({ indent: true })
event.node.res.setHeader('content-type', 'text/xml')
event.node.res.end(feedString)
})

0 comments on commit ef163e6

Please sign in to comment.