-
Notifications
You must be signed in to change notification settings - Fork 2
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 #129 from thematters/feat/new-ui
feat: support build xml and json feed
- Loading branch information
Showing
10 changed files
with
355 additions
and
30 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,16 +1,45 @@ | ||
import { uniqBy } from 'lodash' | ||
|
||
import { HomepageContext } from '../types' | ||
import { renderArticlePage, renderHomepage } from '../render' | ||
import { encrypt } from '../utils' | ||
import { renderHomepage } from '../render' | ||
import { stripSpaces } from '../render/utils' | ||
|
||
export type MakeHomepageData = HomepageContext | ||
|
||
/** | ||
* Make Homepage HTML from articles data | ||
*/ | ||
export const makeHomepage = (data: MakeHomepageData) => { | ||
const html = renderHomepage(data) | ||
const makeHomepageJSONFeed = (data: MakeHomepageData) => { | ||
const feed = { | ||
version: 'https://jsonfeed.org/version/1.1', | ||
title: data.meta.title, | ||
icon: data.meta.image, | ||
home_page_url: data.byline.author.uri, | ||
// feed_url, | ||
description: data.meta.description, | ||
authors: [ | ||
{ | ||
name: data.byline.author.name, | ||
url: data.byline.author.uri, | ||
avatar: data.meta.image, | ||
}, | ||
], | ||
items: data.articles.map((article) => ({ | ||
id: article.id, | ||
title: article.title, | ||
image: article.image, | ||
content_html: article.content, | ||
summary: stripSpaces(article.summary), | ||
date_published: new Date(article.date).toISOString(), | ||
tags: article.tags, | ||
url: article.uri, | ||
external_url: article.sourceUri, | ||
})), | ||
} | ||
|
||
return html | ||
return JSON.stringify(feed, null, 2) | ||
} | ||
|
||
export const makeHomepage = (data: MakeHomepageData) => { | ||
const { html, xml } = renderHomepage(data) | ||
const json = makeHomepageJSONFeed(data) | ||
return { html, xml, json } | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<rss version="2.0" | ||
xmlns:dc="http://purl.org/dc/elements/1.1/" | ||
xmlns:content="http://purl.org/rss/1.0/modules/content/" | ||
xmlns:atom="http://www.w3.org/2005/Atom" | ||
xmlns:media="http://search.yahoo.com/mrss/"> | ||
|
||
<channel> | ||
<title><![CDATA[{{ meta.title | escape }}]]></title> | ||
<link>{{ byline.author.uri }}</link> | ||
<description><![CDATA[{{ meta.description | escape }}]]></description> | ||
|
||
{% if meta.image %} | ||
<image> | ||
<url>{{ meta.image }}</url> | ||
<title><![CDATA[{{ meta.title | escape }}]]></title> | ||
<link>{{ byline.author.uri }}</link> | ||
</image> | ||
{% endif %} | ||
|
||
{% for article in articles %} | ||
<item> | ||
<title><![CDATA[{{ article.title | escape }}]]></title> | ||
<guid>{{ article.sourceUri }}</guid> | ||
<link>{{ article.sourceUri }}</link> | ||
<pubDate>{{ article.date | toRFC822Date }}</pubDate> | ||
<description><![CDATA[{{ article.summary | stripSpaces | escape }}]]></description> | ||
</item> | ||
{% endfor %} | ||
</channel> | ||
|
||
</rss> |
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