parent
39ecabb8f7
commit
5e24c70091
4 changed files with 10 additions and 11 deletions
|
@ -1,29 +1,24 @@
|
||||||
const markdownIt = require('markdown-it')
|
|
||||||
|
|
||||||
const { URL } = require('url')
|
const { URL } = require('url')
|
||||||
const BASE_URL = 'https://coryd.dev'
|
const BASE_URL = 'https://coryd.dev'
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
normalizeEntries: (entries) => {
|
normalizeEntries: (entries) => {
|
||||||
// md instance
|
|
||||||
const md = markdownIt({ html: true, linkify: true })
|
|
||||||
const posts = []
|
const posts = []
|
||||||
|
|
||||||
entries.forEach((entry) => {
|
entries.forEach((entry) => {
|
||||||
const dateKey = Object.keys(entry).find((key) => key.includes('date'))
|
const dateKey = Object.keys(entry).find((key) => key.includes('date'))
|
||||||
const date = new Date(entry[dateKey])
|
const date = new Date(entry[dateKey])
|
||||||
let excerpt = ''
|
let excerpt = ''
|
||||||
|
|
||||||
// set the entry excerpt
|
// set the entry excerpt
|
||||||
|
if (entry.data?.post_excerpt) excerpt = entry.data.post_excerpt
|
||||||
if (entry.description) excerpt = entry.description
|
if (entry.description) excerpt = entry.description
|
||||||
if (entry.data?.post_excerpt) excerpt = md.render(entry.data.post_excerpt)
|
|
||||||
|
|
||||||
// if there's a valid entry return a normalized object
|
// if there's a valid entry return a normalized object
|
||||||
if (entry && !entry.data?.link) {
|
if (entry && !entry.data?.link) {
|
||||||
posts.push({
|
posts.push({
|
||||||
title: entry.data?.title || entry.title,
|
title: entry.data?.title || entry.title,
|
||||||
url: entry.url.includes('http') ? entry.url : new URL(entry.url, BASE_URL).toString(),
|
url: entry.url.includes('http') ? entry.url : new URL(entry.url, BASE_URL).toString(),
|
||||||
content: excerpt,
|
content: entry.description,
|
||||||
date,
|
date,
|
||||||
excerpt,
|
excerpt,
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
const marked = require('marked')
|
||||||
const sanitizeHTML = require('sanitize-html')
|
const sanitizeHTML = require('sanitize-html')
|
||||||
|
|
||||||
const utmPattern = /[?&](utm_[^&=]+=[^&#]*)/gi
|
const utmPattern = /[?&](utm_[^&=]+=[^&#]*)/gi
|
||||||
|
@ -10,6 +11,9 @@ module.exports = {
|
||||||
stripIndex: (path) => {
|
stripIndex: (path) => {
|
||||||
return path.replace('/index.html', '/')
|
return path.replace('/index.html', '/')
|
||||||
},
|
},
|
||||||
|
mdToHtml: (content) => {
|
||||||
|
return marked.parse(content)
|
||||||
|
},
|
||||||
btoa: (string) => {
|
btoa: (string) => {
|
||||||
return btoa(string)
|
return btoa(string)
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
"items": [{% for entry in entries limit: 20 -%}
|
"items": [{% for entry in entries limit: 20 -%}
|
||||||
{
|
{
|
||||||
"id": "{{ entry.url | btoa }}",
|
"id": "{{ entry.url | btoa }}",
|
||||||
"title": "{{ entry.title }}",
|
"title": "{{ entry.title | escape }}",
|
||||||
"url": "{{ entry.url }}",
|
"url": "{{ entry.url }}",
|
||||||
"content_text": "{{ entry.title }}{% if tagMap %} {{ entry.url | tagLookup: tagMap }}{% endif %} {{ entry.url }}",
|
"content_text": "{{ entry.title | escape }}{% if tagMap %} {{ entry.url | tagLookup: tagMap }}{% endif %} {{ entry.url }}",
|
||||||
"date_published": "{{ entry.date | stringToDate | dateToRfc822 }}"
|
"date_published": "{{ entry.date | stringToDate | dateToRfc822 }}"
|
||||||
}{% if not forloop.last %},{% endif %}
|
}{% if not forloop.last %},{% endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
|
@ -15,11 +15,11 @@
|
||||||
</image>
|
</image>
|
||||||
{% for entry in entries limit: 20 -%}
|
{% for entry in entries limit: 20 -%}
|
||||||
<item>
|
<item>
|
||||||
<title>{{ entry.title }}</title>
|
<title>{{ entry.title | escape }}</title>
|
||||||
<link>{{ entry.url | stripUtm | encodeAmp }}</link>
|
<link>{{ entry.url | stripUtm | encodeAmp }}</link>
|
||||||
<pubDate>{{ entry.date | stringToDate | dateToRfc822 }}</pubDate>
|
<pubDate>{{ entry.date | stringToDate | dateToRfc822 }}</pubDate>
|
||||||
<guid>{{ entry.url | stripUtm | encodeAmp }}</guid>
|
<guid>{{ entry.url | stripUtm | encodeAmp }}</guid>
|
||||||
<description>{{ entry.excerpt }}</description>
|
<description>{{ entry.excerpt | markdown | escape }}</description>
|
||||||
</item>
|
</item>
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
</channel>
|
</channel>
|
||||||
|
|
Reference in a new issue