-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #337 from appwrite/feat-rss
feat: rss/xml endpoint
- Loading branch information
Showing
8 changed files
with
139 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,9 @@ | ||
import { base } from '$app/paths'; | ||
import type { AuthorData } from '$markdoc/layouts/Author.svelte'; | ||
import type { CategoryData } from '$markdoc/layouts/Category.svelte'; | ||
import type { PostsData } from '$markdoc/layouts/Post.svelte'; | ||
import { posts, authors, categories } from './content'; | ||
|
||
export function load() { | ||
const postsGlob = import.meta.glob('./post/**/*.markdoc', { | ||
eager: true | ||
}); | ||
const authorsGlob = import.meta.glob('./author/**/*.markdoc', { | ||
eager: true | ||
}); | ||
const categoriesGlob = import.meta.glob('./category/**/*.markdoc', { | ||
eager: true | ||
}); | ||
|
||
const posts = Object.entries(postsGlob) | ||
.map(([filepath, postList]) => { | ||
const { frontmatter } = postList as { | ||
frontmatter: PostsData; | ||
}; | ||
const slug = filepath.replace('./', '').replace('/+page.markdoc', ''); | ||
const postName = slug.slice(slug.lastIndexOf('/') + 1); | ||
|
||
return { | ||
title: frontmatter.title, | ||
description: frontmatter.description, | ||
date: new Date(frontmatter.date), | ||
cover: frontmatter.cover, | ||
timeToRead: frontmatter.timeToRead, | ||
author: frontmatter.author, | ||
category: frontmatter.category, | ||
href: `${base}/blog/post/${postName}` | ||
}; | ||
}) | ||
.sort((a, b) => { | ||
return b.date.getTime() - a.date.getTime(); | ||
}); | ||
|
||
const authors = Object.values(authorsGlob).map((authorList) => { | ||
const { frontmatter } = authorList as { | ||
frontmatter: AuthorData; | ||
}; | ||
|
||
return { | ||
name: frontmatter.name, | ||
slug: frontmatter.slug, | ||
role: frontmatter.role, | ||
avatar: frontmatter.avatar, | ||
bio: frontmatter.bio, | ||
twitter: frontmatter.twitter, | ||
linkedin: frontmatter.linkedin, | ||
github: frontmatter.github, | ||
href: `${base}/blog/author/${frontmatter.slug}` | ||
}; | ||
}); | ||
|
||
const categories = Object.values(categoriesGlob).map((categoryList) => { | ||
const { frontmatter } = categoryList as { | ||
frontmatter: CategoryData; | ||
}; | ||
|
||
return { | ||
name: frontmatter.name, | ||
description: frontmatter.description, | ||
href: `${base}/blog/category/${frontmatter.name.toLowerCase()}` | ||
}; | ||
}); | ||
|
||
return { | ||
posts, | ||
authors, | ||
categories | ||
}; | ||
return { | ||
posts, | ||
authors, | ||
categories | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { base } from '$app/paths'; | ||
export type CategoryData = { | ||
name: string; | ||
description: string; | ||
href: string; | ||
}; | ||
export type AuthorData = { | ||
name: string; | ||
slug: string; | ||
role: string; | ||
avatar: string; | ||
bio: string; | ||
twitter: string; | ||
linkedin: string; | ||
github: string; | ||
href: string; | ||
}; | ||
export type PostsData = { | ||
title: string; | ||
description: string; | ||
date: Date; | ||
cover: string; | ||
timeToRead: number; | ||
author: string; | ||
category: string; | ||
href: string; | ||
featured?: boolean; | ||
}; | ||
|
||
const postsGlob = import.meta.glob('./post/**/*.markdoc', { | ||
eager: true | ||
}); | ||
const authorsGlob = import.meta.glob('./author/**/*.markdoc', { | ||
eager: true | ||
}); | ||
const categoriesGlob = import.meta.glob('./category/**/*.markdoc', { | ||
eager: true | ||
}); | ||
|
||
export const posts = Object.entries(postsGlob) | ||
.map(([filepath, postList]) => { | ||
const { frontmatter } = postList as { | ||
frontmatter: PostsData; | ||
}; | ||
const slug = filepath.replace('./', '').replace('/+page.markdoc', ''); | ||
const postName = slug.slice(slug.lastIndexOf('/') + 1); | ||
|
||
return { | ||
title: frontmatter.title, | ||
description: frontmatter.description, | ||
date: new Date(frontmatter.date), | ||
cover: frontmatter.cover, | ||
timeToRead: frontmatter.timeToRead, | ||
author: frontmatter.author, | ||
category: frontmatter.category, | ||
href: `${base}/blog/post/${postName}` | ||
}; | ||
}) | ||
.sort((a, b) => { | ||
return b.date.getTime() - a.date.getTime(); | ||
}); | ||
|
||
export const authors = Object.values(authorsGlob).map((authorList) => { | ||
const { frontmatter } = authorList as { | ||
frontmatter: AuthorData; | ||
}; | ||
|
||
return { | ||
name: frontmatter.name, | ||
slug: frontmatter.slug, | ||
role: frontmatter.role, | ||
avatar: frontmatter.avatar, | ||
bio: frontmatter.bio, | ||
twitter: frontmatter.twitter, | ||
linkedin: frontmatter.linkedin, | ||
github: frontmatter.github, | ||
href: `${base}/blog/author/${frontmatter.slug}` | ||
}; | ||
}); | ||
|
||
export const categories = Object.values(categoriesGlob).map((categoryList) => { | ||
const { frontmatter } = categoryList as { | ||
frontmatter: CategoryData; | ||
}; | ||
|
||
return { | ||
name: frontmatter.name, | ||
description: frontmatter.description, | ||
href: `${base}/blog/category/${frontmatter.name.toLowerCase()}` | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { RequestHandler } from './$types'; | ||
import { posts } from '../content'; | ||
import { json } from '@sveltejs/kit'; | ||
|
||
export const prerender = true; | ||
|
||
export const GET: RequestHandler = () => { | ||
return json({ | ||
posts, | ||
total: Object.keys(posts).length | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { RequestHandler } from './$types'; | ||
import { posts } from '../content'; | ||
|
||
export const prerender = true; | ||
|
||
export const GET: RequestHandler = () => { | ||
const feed = `<?xml version="1.0" encoding="UTF-8" ?> | ||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> | ||
<channel> | ||
<title>Appwrite</title> | ||
<link>https://appwrite.io</link> | ||
<description>Appwrite is an open-source platform for building applications at any scale, using your preferred programming languages and tools.</description> | ||
${posts.map((post) => `<item> | ||
<title>${post.title}</title> | ||
<pubDate>${post.date.toUTCString()}</pubDate> | ||
<link>https://appwrite.io${post.href}</link> | ||
<guid>https://appwrite.io${post.href}</guid> | ||
<description>${post.description}</description> | ||
</item> | ||
`).join('')} | ||
</channel> | ||
</rss>`; | ||
|
||
return new Response(feed); | ||
}; |