fix: wrangle urls
This commit is contained in:
parent
c1e0088942
commit
8e0119b2f7
5 changed files with 17 additions and 8 deletions
|
@ -12,6 +12,15 @@ module.exports = {
|
|||
return marked.parse(content)
|
||||
},
|
||||
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) => {
|
||||
if (image && image !== '') return image
|
||||
return '/assets/img/social-card.webp'
|
||||
|
|
|
@ -10,9 +10,9 @@ permalink: /books.xml
|
|||
{% for book in books %}
|
||||
<entry>
|
||||
<title>{{ book.title | escape }}</title>
|
||||
<link href="{{ book.link }}" />
|
||||
<link href="{{ book.link | stripUtm | encodeAmp }}" />
|
||||
<updated>{{ book.dateAdded | date: "%m.%d.%Y" }}</updated>
|
||||
<id>{{ book.link | url_encode }}</id>
|
||||
<id>{{ book.link | stripUtm | encodeAmp }}</id>
|
||||
<content type="html"></content>
|
||||
</entry>
|
||||
{% endfor %}
|
||||
|
|
|
@ -9,9 +9,9 @@ permalink: '/books.json'
|
|||
"feed_url": "https://coryd.dev/books.json",
|
||||
"items": [{% for book in books %}
|
||||
{
|
||||
"id": "{{ book.link }}",
|
||||
"id": "{{ book.link | stripUtm | encodeAmp }}",
|
||||
"title": "{{ book.title | escape }}",
|
||||
"url": "{{ book.link }}",
|
||||
"url": "{{ book.link | stripUtm | encodeAmp }}",
|
||||
"content_text": "{{ book.description | strip_html }}",
|
||||
"date_published": "{{ book.dateAdded | date: "%Y-%m-%dT%H:%M:%S-08:00" }}"
|
||||
}{% if not forloop.last %},{% endif %}
|
||||
|
|
|
@ -9,9 +9,9 @@ permalink: '/links.json'
|
|||
"feed_url": "https://coryd.dev/links.json",
|
||||
"items": [{% for link in links %}
|
||||
{
|
||||
"id": "{{ link.id }}",
|
||||
"id": "{{ link.url | stripUtm | encodeAmp }}",
|
||||
"title": "{{ link.title | escape }}",
|
||||
"url": "{{ link.url }}",
|
||||
"url": "{{ link.url | stripUtm | encodeAmp }}",
|
||||
"content_text": "{{ link.summary | escape }}",
|
||||
"date_published": "{{ link.date | date: "%Y-%m-%dT%H:%M:%S-08:00" }}"
|
||||
}{% if not forloop.last %},{% endif %}
|
||||
|
|
|
@ -10,9 +10,9 @@ permalink: /links.xml
|
|||
{% for link in links %}
|
||||
<entry>
|
||||
<title>{{ link.title | escape }}</title>
|
||||
<link href="{{ link.url }}" />
|
||||
<link href="{{ link.url | stripUtm | encodeAmp }}" />
|
||||
<updated>{{ link.date | date: "%m.%d.%Y" }}</updated>
|
||||
<id>{{ link.url | url_encode }}</id>
|
||||
<id>{{ link.url | stripUtm | encodeAmp }}</id>
|
||||
<content type="html"></content>
|
||||
</entry>
|
||||
{% endfor %}
|
||||
|
|
Reference in a new issue