fix: wrangle urls

This commit is contained in:
Cory Dransfeldt 2023-08-04 13:17:00 -07:00
parent c1e0088942
commit 8e0119b2f7
No known key found for this signature in database
5 changed files with 17 additions and 8 deletions

View file

@ -12,6 +12,15 @@ module.exports = {
return marked.parse(content) return marked.parse(content)
}, },
dashLower: (string) => string.replace(/\s+/g, '-').toLowerCase(), dashLower: (string) => string.replace(/\s+/g, '-').toLowerCase(),
encodeAmp: (string) => {
const pattern = /&(?!(?:[a-zA-Z]+|#[0-9]+|#x[0-9a-fA-F]+);)/g
const replacement = '&'
return string.replace(pattern, replacement)
},
stripUtm: (string) => {
const pattern = /[?&](utm_[^&=]+=[^&#]*)/gi
return string.replace(pattern, '')
},
getPostImage: (image) => { getPostImage: (image) => {
if (image && image !== '') return image if (image && image !== '') return image
return '/assets/img/social-card.webp' return '/assets/img/social-card.webp'

View file

@ -10,9 +10,9 @@ permalink: /books.xml
{% for book in books %} {% for book in books %}
<entry> <entry>
<title>{{ book.title | escape }}</title> <title>{{ book.title | escape }}</title>
<link href="{{ book.link }}" /> <link href="{{ book.link | stripUtm | encodeAmp }}" />
<updated>{{ book.dateAdded | date: "%m.%d.%Y" }}</updated> <updated>{{ book.dateAdded | date: "%m.%d.%Y" }}</updated>
<id>{{ book.link | url_encode }}</id> <id>{{ book.link | stripUtm | encodeAmp }}</id>
<content type="html"></content> <content type="html"></content>
</entry> </entry>
{% endfor %} {% endfor %}

View file

@ -9,9 +9,9 @@ permalink: '/books.json'
"feed_url": "https://coryd.dev/books.json", "feed_url": "https://coryd.dev/books.json",
"items": [{% for book in books %} "items": [{% for book in books %}
{ {
"id": "{{ book.link }}", "id": "{{ book.link | stripUtm | encodeAmp }}",
"title": "{{ book.title | escape }}", "title": "{{ book.title | escape }}",
"url": "{{ book.link }}", "url": "{{ book.link | stripUtm | encodeAmp }}",
"content_text": "{{ book.description | strip_html }}", "content_text": "{{ book.description | strip_html }}",
"date_published": "{{ book.dateAdded | date: "%Y-%m-%dT%H:%M:%S-08:00" }}" "date_published": "{{ book.dateAdded | date: "%Y-%m-%dT%H:%M:%S-08:00" }}"
}{% if not forloop.last %},{% endif %} }{% if not forloop.last %},{% endif %}

View file

@ -9,9 +9,9 @@ permalink: '/links.json'
"feed_url": "https://coryd.dev/links.json", "feed_url": "https://coryd.dev/links.json",
"items": [{% for link in links %} "items": [{% for link in links %}
{ {
"id": "{{ link.id }}", "id": "{{ link.url | stripUtm | encodeAmp }}",
"title": "{{ link.title | escape }}", "title": "{{ link.title | escape }}",
"url": "{{ link.url }}", "url": "{{ link.url | stripUtm | encodeAmp }}",
"content_text": "{{ link.summary | escape }}", "content_text": "{{ link.summary | escape }}",
"date_published": "{{ link.date | date: "%Y-%m-%dT%H:%M:%S-08:00" }}" "date_published": "{{ link.date | date: "%Y-%m-%dT%H:%M:%S-08:00" }}"
}{% if not forloop.last %},{% endif %} }{% if not forloop.last %},{% endif %}

View file

@ -10,9 +10,9 @@ permalink: /links.xml
{% for link in links %} {% for link in links %}
<entry> <entry>
<title>{{ link.title | escape }}</title> <title>{{ link.title | escape }}</title>
<link href="{{ link.url }}" /> <link href="{{ link.url | stripUtm | encodeAmp }}" />
<updated>{{ link.date | date: "%m.%d.%Y" }}</updated> <updated>{{ link.date | date: "%m.%d.%Y" }}</updated>
<id>{{ link.url | url_encode }}</id> <id>{{ link.url | stripUtm | encodeAmp }}</id>
<content type="html"></content> <content type="html"></content>
</entry> </entry>
{% endfor %} {% endfor %}