Skip to content

Commit 861b6c2

Browse files
Merge pull request #337 from appwrite/feat-rss
feat: rss/xml endpoint
2 parents 95926b2 + 06965b4 commit 861b6c2

File tree

8 files changed

+139
-115
lines changed

8 files changed

+139
-115
lines changed

src/markdoc/layouts/Author.svelte

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
1-
<script context="module" lang="ts">
2-
export type AuthorData = {
3-
name: string;
4-
slug: string;
5-
role: string;
6-
avatar: string;
7-
bio: string;
8-
twitter: string;
9-
linkedin: string;
10-
github: string;
11-
href: string;
12-
};
13-
</script>
14-
151
<script lang="ts">
162
import { Article, FooterNav, MainFooter } from '$lib/components';
173
import { page } from '$app/stores';
184
import { Main } from '$lib/layouts';
195
import { getContext } from 'svelte';
20-
import type { PostsData } from './Post.svelte';
216
import { BLOG_TITLE_SUFFIX } from '$routes/titles';
7+
import type { PostsData, AuthorData } from '$routes/blog/content';
228
import { DEFAULT_HOST } from '$lib/utils/metadata';
239
import FloatingHead from '$lib/components/FloatingHead.svelte';
2410

src/markdoc/layouts/Category.svelte

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
1-
<script context="module" lang="ts">
2-
export type CategoryData = {
3-
name: string;
4-
description: string;
5-
href: string;
6-
};
7-
</script>
8-
91
<script lang="ts">
102
import { Article, FooterNav, MainFooter } from '$lib/components';
113
import { Main } from '$lib/layouts';
124
import { getContext } from 'svelte';
13-
import type { PostsData } from './Post.svelte';
14-
import type { AuthorData } from './Author.svelte';
5+
import type { PostsData, AuthorData } from '$routes/blog/content';
156
import { BLOG_TITLE_SUFFIX } from '$routes/titles';
167
import { DEFAULT_HOST } from '$lib/utils/metadata';
178

src/markdoc/layouts/Post.svelte

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
1-
<script context="module" lang="ts">
2-
export type PostsData = {
3-
title: string;
4-
description: string;
5-
date: Date;
6-
cover: string;
7-
timeToRead: number;
8-
author: string;
9-
category: string;
10-
href: string;
11-
featured?: boolean;
12-
};
13-
</script>
14-
151
<script lang="ts">
162
import { Article, FooterNav, MainFooter, Newsletter } from '$lib/components';
173
import { Main } from '$lib/layouts';
184
import { getContext } from 'svelte';
19-
import type { AuthorData } from './Author.svelte';
20-
import type { CategoryData } from './Category.svelte';
5+
import type { CategoryData, AuthorData, PostsData } from '$routes/blog/content';
216
import { BLOG_TITLE_SUFFIX } from '$routes/titles';
227
import { DEFAULT_HOST } from '$lib/utils/metadata';
238

src/routes/blog/+layout.ts

Lines changed: 6 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,9 @@
1-
import { base } from '$app/paths';
2-
import type { AuthorData } from '$markdoc/layouts/Author.svelte';
3-
import type { CategoryData } from '$markdoc/layouts/Category.svelte';
4-
import type { PostsData } from '$markdoc/layouts/Post.svelte';
1+
import { posts, authors, categories } from './content';
52

63
export function load() {
7-
const postsGlob = import.meta.glob('./post/**/*.markdoc', {
8-
eager: true
9-
});
10-
const authorsGlob = import.meta.glob('./author/**/*.markdoc', {
11-
eager: true
12-
});
13-
const categoriesGlob = import.meta.glob('./category/**/*.markdoc', {
14-
eager: true
15-
});
16-
17-
const posts = Object.entries(postsGlob)
18-
.map(([filepath, postList]) => {
19-
const { frontmatter } = postList as {
20-
frontmatter: PostsData;
21-
};
22-
const slug = filepath.replace('./', '').replace('/+page.markdoc', '');
23-
const postName = slug.slice(slug.lastIndexOf('/') + 1);
24-
25-
return {
26-
title: frontmatter.title,
27-
description: frontmatter.description,
28-
date: new Date(frontmatter.date),
29-
cover: frontmatter.cover,
30-
timeToRead: frontmatter.timeToRead,
31-
author: frontmatter.author,
32-
category: frontmatter.category,
33-
href: `${base}/blog/post/${postName}`
34-
};
35-
})
36-
.sort((a, b) => {
37-
return b.date.getTime() - a.date.getTime();
38-
});
39-
40-
const authors = Object.values(authorsGlob).map((authorList) => {
41-
const { frontmatter } = authorList as {
42-
frontmatter: AuthorData;
43-
};
44-
45-
return {
46-
name: frontmatter.name,
47-
slug: frontmatter.slug,
48-
role: frontmatter.role,
49-
avatar: frontmatter.avatar,
50-
bio: frontmatter.bio,
51-
twitter: frontmatter.twitter,
52-
linkedin: frontmatter.linkedin,
53-
github: frontmatter.github,
54-
href: `${base}/blog/author/${frontmatter.slug}`
55-
};
56-
});
57-
58-
const categories = Object.values(categoriesGlob).map((categoryList) => {
59-
const { frontmatter } = categoryList as {
60-
frontmatter: CategoryData;
61-
};
62-
63-
return {
64-
name: frontmatter.name,
65-
description: frontmatter.description,
66-
href: `${base}/blog/category/${frontmatter.name.toLowerCase()}`
67-
};
68-
});
69-
70-
return {
71-
posts,
72-
authors,
73-
categories
74-
};
4+
return {
5+
posts,
6+
authors,
7+
categories
8+
};
759
}

src/routes/blog/content.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { base } from '$app/paths';
2+
export type CategoryData = {
3+
name: string;
4+
description: string;
5+
href: string;
6+
};
7+
export type AuthorData = {
8+
name: string;
9+
slug: string;
10+
role: string;
11+
avatar: string;
12+
bio: string;
13+
twitter: string;
14+
linkedin: string;
15+
github: string;
16+
href: string;
17+
};
18+
export type PostsData = {
19+
title: string;
20+
description: string;
21+
date: Date;
22+
cover: string;
23+
timeToRead: number;
24+
author: string;
25+
category: string;
26+
href: string;
27+
featured?: boolean;
28+
};
29+
30+
const postsGlob = import.meta.glob('./post/**/*.markdoc', {
31+
eager: true
32+
});
33+
const authorsGlob = import.meta.glob('./author/**/*.markdoc', {
34+
eager: true
35+
});
36+
const categoriesGlob = import.meta.glob('./category/**/*.markdoc', {
37+
eager: true
38+
});
39+
40+
export const posts = Object.entries(postsGlob)
41+
.map(([filepath, postList]) => {
42+
const { frontmatter } = postList as {
43+
frontmatter: PostsData;
44+
};
45+
const slug = filepath.replace('./', '').replace('/+page.markdoc', '');
46+
const postName = slug.slice(slug.lastIndexOf('/') + 1);
47+
48+
return {
49+
title: frontmatter.title,
50+
description: frontmatter.description,
51+
date: new Date(frontmatter.date),
52+
cover: frontmatter.cover,
53+
timeToRead: frontmatter.timeToRead,
54+
author: frontmatter.author,
55+
category: frontmatter.category,
56+
href: `${base}/blog/post/${postName}`
57+
};
58+
})
59+
.sort((a, b) => {
60+
return b.date.getTime() - a.date.getTime();
61+
});
62+
63+
export const authors = Object.values(authorsGlob).map((authorList) => {
64+
const { frontmatter } = authorList as {
65+
frontmatter: AuthorData;
66+
};
67+
68+
return {
69+
name: frontmatter.name,
70+
slug: frontmatter.slug,
71+
role: frontmatter.role,
72+
avatar: frontmatter.avatar,
73+
bio: frontmatter.bio,
74+
twitter: frontmatter.twitter,
75+
linkedin: frontmatter.linkedin,
76+
github: frontmatter.github,
77+
href: `${base}/blog/author/${frontmatter.slug}`
78+
};
79+
});
80+
81+
export const categories = Object.values(categoriesGlob).map((categoryList) => {
82+
const { frontmatter } = categoryList as {
83+
frontmatter: CategoryData;
84+
};
85+
86+
return {
87+
name: frontmatter.name,
88+
description: frontmatter.description,
89+
href: `${base}/blog/category/${frontmatter.name.toLowerCase()}`
90+
};
91+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { RequestHandler } from './$types';
2+
import { posts } from '../content';
3+
import { json } from '@sveltejs/kit';
4+
5+
export const prerender = true;
6+
7+
export const GET: RequestHandler = () => {
8+
return json({
9+
posts,
10+
total: Object.keys(posts).length
11+
});
12+
};

src/routes/blog/post/migrate-firebase-projects-to-appwrite/+page.markdoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ To help you with your move, Appwrite Migrations will require keys to your old ho
2828

2929
![Firebase key management screen.](/images/blog/migrate-firebase-projects-to-appwrite/firebase-key.png)
3030

31-
The quickest way to get a key is to use your ****Firebase Admin SDK**** service account and key, found under ****Project settings > Service accounts > Generate private key****.
31+
The quickest way to get a key is to use your **Firebase Admin SDK** service account and key, found under **Project settings > Service accounts > Generate private key**.
3232

3333
If you want to use an API key with a more fine-grained permission scope, checkout the [Appwrite documentation on this topic](/docs/advanced/migrations/firebase).
3434

@@ -39,7 +39,7 @@ The Migration process is simple. Give Appwrite your keys, and it’ll pack up an
3939
1. Create a new project and click on the **Migrations** tab in **Project Settings**.
4040
2. Click on the **Create Migration** button and select **Firebase** as your source.
4141
3. Paste your Firebase API key’s JSON contents into the account credentials box and click **Next.**
42-
4. Select which resources you want Migrations to import and click ************Create************ to start the migration.
42+
4. Select which resources you want Migrations to import and click **Create** to start the migration.
4343

4444
Migrations will run in the background, get a cup of tea or coffee, and return in a few minutes.
4545

src/routes/blog/rss.xml/+server.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { RequestHandler } from './$types';
2+
import { posts } from '../content';
3+
4+
export const prerender = true;
5+
6+
export const GET: RequestHandler = () => {
7+
const feed = `<?xml version="1.0" encoding="UTF-8" ?>
8+
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
9+
<channel>
10+
<title>Appwrite</title>
11+
<link>https://appwrite.io</link>
12+
<description>Appwrite is an open-source platform for building applications at any scale, using your preferred programming languages and tools.</description>
13+
${posts.map((post) => `<item>
14+
<title>${post.title}</title>
15+
<pubDate>${post.date.toUTCString()}</pubDate>
16+
<link>https://appwrite.io${post.href}</link>
17+
<guid>https://appwrite.io${post.href}</guid>
18+
<description>${post.description}</description>
19+
</item>
20+
`).join('')}
21+
</channel>
22+
</rss>`;
23+
24+
return new Response(feed);
25+
};

0 commit comments

Comments
 (0)