mirror of
https://github.com/hyprwm/hyprland-website.git
synced 2024-11-16 18:35:59 +01:00
fix RSS not showing in prod (#45)
This commit is contained in:
parent
821d96b466
commit
ddbed7d075
6 changed files with 28 additions and 28 deletions
|
@ -5,7 +5,7 @@
|
||||||
<link rel="icon" href="%sveltekit.assets%/favicon.ico" />
|
<link rel="icon" href="%sveltekit.assets%/favicon.ico" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
<meta property="og:image" content="/imgs/og-img.png" />
|
<meta property="og:image" content="/imgs/og-img.png" />
|
||||||
<link rel="alternate" type="application/rss+xml" title="Hyprland News" href="/rss" />
|
<link rel="alternate" type="application/rss+xml" title="Hyprland News" href="/rss.xml" />
|
||||||
<style></style>
|
<style></style>
|
||||||
%sveltekit.head%
|
%sveltekit.head%
|
||||||
</head>
|
</head>
|
||||||
|
|
|
@ -78,7 +78,7 @@
|
||||||
</li>
|
</li>
|
||||||
<li class="">
|
<li class="">
|
||||||
<a
|
<a
|
||||||
href="/rss"
|
href="/rss.xml"
|
||||||
class="text-slate-400 hover:text-slate-200"
|
class="text-slate-400 hover:text-slate-200"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
aria-label="Rss Feed"><RssIcon class="h-12 w-12 " /></a
|
aria-label="Rss Feed"><RssIcon class="h-12 w-12 " /></a
|
||||||
|
|
18
src/lib/posts.js
Normal file
18
src/lib/posts.js
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
export async function getNews() {
|
||||||
|
const posts = Object.entries(import.meta.glob('/src/content/news/*.md', { eager: true }))
|
||||||
|
.flatMap(([path, { metadata }]) => {
|
||||||
|
const slug = path.split('/').at(-1)?.replace('.md', '')
|
||||||
|
const rawDate = metadata.date
|
||||||
|
const date = new Date(typeof rawDate === 'number' ? rawDate * 1000 : rawDate).getTime()
|
||||||
|
|
||||||
|
if (!slug || !path || Number.isNaN(date)) {
|
||||||
|
console.error(`Invalid file ${path} ${JSON.stringify({ ...metadata, date, slug })}`)
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
return { slug, ...metadata, date }
|
||||||
|
})
|
||||||
|
.sort(({ date: a }, { date: b }) => new Date(b).getTime() - new Date(a).getTime())
|
||||||
|
|
||||||
|
return posts
|
||||||
|
}
|
|
@ -1,24 +1,6 @@
|
||||||
|
import { getNews } from '$lib/posts'
|
||||||
import { json } from '@sveltejs/kit'
|
import { json } from '@sveltejs/kit'
|
||||||
|
|
||||||
async function getNews() {
|
|
||||||
const posts = Object.entries(import.meta.glob('/src/content/news/*.md', { eager: true }))
|
|
||||||
.flatMap(([path, { metadata }]) => {
|
|
||||||
const slug = path.split('/').at(-1)?.replace('.md', '')
|
|
||||||
const rawDate = metadata.date
|
|
||||||
const date = new Date(typeof rawDate === 'number' ? rawDate * 1000 : rawDate).getTime()
|
|
||||||
|
|
||||||
if (!slug || !path || Number.isNaN(date)) {
|
|
||||||
console.error(`Invalid file ${path} ${JSON.stringify({ ...metadata, date, slug })}`)
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
return { slug, ...metadata, date }
|
|
||||||
})
|
|
||||||
.sort(({ date: a }, { date: b }) => new Date(b).getTime() - new Date(a).getTime())
|
|
||||||
|
|
||||||
return posts
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
const news = await getNews()
|
const news = await getNews()
|
||||||
return json(news)
|
return json(news)
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import { error } from '@sveltejs/kit'
|
|
||||||
|
|
||||||
export async function load({ params, fetch }) {
|
export async function load({ params, fetch }) {
|
||||||
try {
|
try {
|
||||||
const post = await import(`../../../content/news/${params.slug}.md`)
|
const post = await import(`../../../content/news/${params.slug}.md`)
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
|
import { getNews } from '$lib/posts'
|
||||||
|
|
||||||
const siteURL = 'https://hyprland.org'
|
const siteURL = 'https://hyprland.org'
|
||||||
const siteTitle = 'Hyprland'
|
const siteTitle = 'Hyprland'
|
||||||
const siteDescription = 'Tiling window manager with the looks'
|
const siteDescription = 'Tiling window manager with the looks'
|
||||||
|
|
||||||
export const prerender = true
|
export const prerender = true
|
||||||
|
|
||||||
export const GET = async ({ fetch }) => {
|
export const GET = async () => {
|
||||||
const allNews = await fetch('api/news')
|
const allNews = await getNews().then((news) =>
|
||||||
.then((response) => response.json())
|
news.sort((a, b) => new Date(b.date) - new Date(a.date))
|
||||||
.then((news) => news.sort((a, b) => new Date(b.date) - new Date(a.date)))
|
)
|
||||||
|
|
||||||
const body = renderXml(allNews)
|
const body = renderXml(allNews)
|
||||||
const options = {
|
const options = {
|
||||||
|
@ -24,7 +26,7 @@ function renderXml(posts) {
|
||||||
return `<?xml version="1.0" encoding="UTF-8" ?>
|
return `<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||||
<channel>
|
<channel>
|
||||||
<atom:link href="${siteURL}/rss" rel="self" type="application/rss+xml" />
|
<atom:link href="${siteURL}/rss.xml" rel="self" type="application/rss+xml" />
|
||||||
<title>${siteTitle} News</title>
|
<title>${siteTitle} News</title>
|
||||||
<link>${siteURL}/news</link>
|
<link>${siteURL}/news</link>
|
||||||
<description>${siteDescription}</description>
|
<description>${siteDescription}</description>
|
Loading…
Reference in a new issue