Skip to content

Commit

Permalink
Merge pull request #337 from appwrite/feat-rss
Browse files Browse the repository at this point in the history
feat: rss/xml endpoint
  • Loading branch information
TorstenDittmann authored Nov 9, 2023
2 parents 95926b2 + 06965b4 commit 861b6c2
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 115 deletions.
16 changes: 1 addition & 15 deletions src/markdoc/layouts/Author.svelte
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
<script context="module" lang="ts">
export type AuthorData = {
name: string;
slug: string;
role: string;
avatar: string;
bio: string;
twitter: string;
linkedin: string;
github: string;
href: string;
};
</script>

<script lang="ts">
import { Article, FooterNav, MainFooter } from '$lib/components';
import { page } from '$app/stores';
import { Main } from '$lib/layouts';
import { getContext } from 'svelte';
import type { PostsData } from './Post.svelte';
import { BLOG_TITLE_SUFFIX } from '$routes/titles';
import type { PostsData, AuthorData } from '$routes/blog/content';
import { DEFAULT_HOST } from '$lib/utils/metadata';
import FloatingHead from '$lib/components/FloatingHead.svelte';
Expand Down
11 changes: 1 addition & 10 deletions src/markdoc/layouts/Category.svelte
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
<script context="module" lang="ts">
export type CategoryData = {
name: string;
description: string;
href: string;
};
</script>

<script lang="ts">
import { Article, FooterNav, MainFooter } from '$lib/components';
import { Main } from '$lib/layouts';
import { getContext } from 'svelte';
import type { PostsData } from './Post.svelte';
import type { AuthorData } from './Author.svelte';
import type { PostsData, AuthorData } from '$routes/blog/content';
import { BLOG_TITLE_SUFFIX } from '$routes/titles';
import { DEFAULT_HOST } from '$lib/utils/metadata';
Expand Down
17 changes: 1 addition & 16 deletions src/markdoc/layouts/Post.svelte
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
<script context="module" lang="ts">
export type PostsData = {
title: string;
description: string;
date: Date;
cover: string;
timeToRead: number;
author: string;
category: string;
href: string;
featured?: boolean;
};
</script>

<script lang="ts">
import { Article, FooterNav, MainFooter, Newsletter } from '$lib/components';
import { Main } from '$lib/layouts';
import { getContext } from 'svelte';
import type { AuthorData } from './Author.svelte';
import type { CategoryData } from './Category.svelte';
import type { CategoryData, AuthorData, PostsData } from '$routes/blog/content';
import { BLOG_TITLE_SUFFIX } from '$routes/titles';
import { DEFAULT_HOST } from '$lib/utils/metadata';
Expand Down
78 changes: 6 additions & 72 deletions src/routes/blog/+layout.ts
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
};
}
91 changes: 91 additions & 0 deletions src/routes/blog/content.ts
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()}`
};
});
12 changes: 12 additions & 0 deletions src/routes/blog/feed.json/+server.ts
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
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ To help you with your move, Appwrite Migrations will require keys to your old ho

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

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****.
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**.

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).

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

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

Expand Down
25 changes: 25 additions & 0 deletions src/routes/blog/rss.xml/+server.ts
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);
};

0 comments on commit 861b6c2

Please sign in to comment.