feat: feed/search/sitemap

This commit is contained in:
Cory Dransfeldt 2024-10-11 19:10:20 -07:00
parent 086cd20788
commit c6d00b2836
No known key found for this signature in database
34 changed files with 198 additions and 535 deletions

19
src/data/activity.js Normal file
View file

@ -0,0 +1,19 @@
import { createClient } from '@supabase/supabase-js'
const SUPABASE_URL = process.env.SUPABASE_URL
const SUPABASE_KEY = process.env.SUPABASE_KEY
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
export default async function fetchSyndication() {
const { data, error } = await supabase
.from('optimized_all_activity')
.select('feed')
if (error) {
console.error('Error fetching search index data:', error)
return []
}
const [{ feed } = {}] = data
return feed?.filter(item => item['feed'] !== null) || []
}

View file

@ -29,9 +29,8 @@ const fetchAlbumReleases = async () => {
}).sort((a, b) => a['timestamp'] - b['timestamp'])
const upcoming = all.filter(album => album['release_timestamp'] > today)
const current = all.filter(album => album['release_timestamp'] <= today)
return { all, upcoming, current }
return { all, upcoming }
}
export default async function () {

View file

@ -29,18 +29,6 @@ const fetchAllBooks = async () => {
return books
}
const processBooks = (books) => {
return books.map(book => {
const dateFinished = book['date_finished'] ? new Date(book['date_finished']) : null
const year = dateFinished && !isNaN(dateFinished.getTime()) ? dateFinished.getUTCFullYear() : null
return {
...book,
year,
}
})
}
const sortBooksByYear = (books) => {
const years = {}
books.forEach(book => {
@ -51,12 +39,11 @@ const sortBooksByYear = (books) => {
years[year]['data'].push(book)
}
})
return Object.values(years).filter(year => year.value > 2017)
return Object.values(years).filter(year => year['value'] > 2017)
}
export default async function () {
const books = await fetchAllBooks()
const processedBooks = processBooks(books)
return { all: processedBooks, years: sortBooksByYear(processedBooks) }
return { all: books, years: sortBooksByYear(books), feed: books.filter(book => book['feed']) }
}

View file

@ -35,15 +35,15 @@ export default async function () {
try {
const movies = await fetchAllMovies()
const filterMovies = (condition) => movies.filter(condition)
const favoriteMovies = filterMovies(movie => movie.favorite)
const recentlyWatchedMovies = filterMovies(movie => movie.last_watched && year - DateTime.fromISO(movie.last_watched).year <= 3)
const favoriteMovies = movies.filter(movie => movie['favorite'])
const recentlyWatchedMovies = movies.filter(movie => movie['last_watched'] && year - DateTime.fromISO(movie['last_watched']).year <= 3)
return {
movies,
watchHistory: filterMovies(movie => movie.last_watched),
watchHistory: movies.filter(movie => movie['last_watched']),
recentlyWatched: recentlyWatchedMovies,
favorites: favoriteMovies.sort((a, b) => a.title.localeCompare(b.title)),
favorites: favoriteMovies.sort((a, b) => a['title'].localeCompare(b['title'])),
feed: movies.filter(movie => movie['feed']),
}
} catch (error) {
console.error('Error fetching and processing movies data:', error)
@ -51,7 +51,8 @@ export default async function () {
movies: [],
watchHistory: [],
recentlyWatched: [],
favorites: []
favorites: [],
feed: []
}
}
}

19
src/data/search.js Normal file
View file

@ -0,0 +1,19 @@
import { createClient } from '@supabase/supabase-js'
const SUPABASE_URL = process.env.SUPABASE_URL
const SUPABASE_KEY = process.env.SUPABASE_KEY
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
export default async function fetchSearchIndex() {
const { data, error } = await supabase
.from('optimized_search_index')
.select('search_index')
if (error) {
console.error('Error fetching search index data:', error)
return []
}
const [{ search_index } = {}] = data
return search_index || []
}

19
src/data/sitemap.js Normal file
View file

@ -0,0 +1,19 @@
import { createClient } from '@supabase/supabase-js'
const SUPABASE_URL = process.env.SUPABASE_URL
const SUPABASE_KEY = process.env.SUPABASE_KEY
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
export default async function fetchSitemap() {
const { data, error } = await supabase
.from('optimized_sitemap')
.select('sitemap')
if (error) {
console.error('Error fetching sitemap data:', error)
return []
}
const [{ sitemap } = {}] = data
return sitemap || []
}

19
src/data/syndication.js Normal file
View file

@ -0,0 +1,19 @@
import { createClient } from '@supabase/supabase-js'
const SUPABASE_URL = process.env.SUPABASE_URL
const SUPABASE_KEY = process.env.SUPABASE_KEY
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
export default async function fetchSyndication() {
const { data, error } = await supabase
.from('optimized_syndication')
.select('syndication')
if (error) {
console.error('Error fetching search index data:', error)
return []
}
const [{ syndication } = {}] = data
return syndication?.filter(item => item['syndication'] !== null) || []
}

View file

@ -1,48 +1,24 @@
{
"version": "https://jsonfeed.org/version/1.1",
"title": "{{ title | escape }}",
"home_page_url": "{{ permalink | absoluteUrl | escape }}",
"feed_url": "{{ permalink | absoluteUrl | escape }}.json",
"description": "{{ globals.site_description | escape }}",
"icon": "https://cdn.coryd.dev{{ globals.avatar | escape }}?class=w200&v={% appVersion %}",
"favicon": "https://cdn.coryd.dev{{ globals.avatar | escape }}?class=w50&v={% appVersion %}",
"authors": [{
"name": "{{ globals.site_name }}",
"url": "{{ globals.url | escape }}",
"avatar": "https://cdn.coryd.dev{{ globals.avatar | escape }}?class=w200&v={% appVersion %}"
}],
"items": [
{%- assign entries = data | normalizeEntries: 20 -%}
{%- for entry in entries -%}
{%- assign summary = entry.content | strip_html | normalize_whitespace | escape -%}
{%- assign utm_parameters = "utm_source=rss&utm_medium=feed&utm_campaign=" | append: utm_campaign -%}
{
"id": "{{ entry.url | encodeAmp | escape }}",
"title": "{{ entry.title | escape }}{% if entry.authors %} via {{ entry.authors.name | escape }}{% endif %}{% if entry.rating %} ({{ entry.rating | escape }}){% endif %}",
{%- if utm_campaign -%}
"url": "{{ entry.url | append: '?' | append: utm_parameters }}",
{%- else -%}
"url": "{{ entry.url | encodeAmp }}",
{%- endif -%}
"content_html": "{{ summary }}",
"summary": "{{ summary }}",
{%- if entry.author -%}
"external_url": "{{ entry.url | encodeAmp | escape }}",
"authors": [{
"name": "{{ entry.author.name | escape }}",
"url": "{{ entry.author.url | escape }}",
"mastodon": "{{ entry.author.mastodon | escape }}",
"rss": "{{ entry.author.feed | escape }}"
}],
{%- endif %}
"date_published": "{{ entry.date | date: '%Y-%m-%dT%H:%M:%S%:z' }}"{%- if entry.tags -%},
"tags": [
{%- for tag in entry.tags -%}
"{{ tag | escape }}"{%- unless forloop.last -%}, {% endunless -%}
{%- endfor -%}
]
{%- endif -%}
}{%- if forloop.last == false -%},{%- endif -%}
{%- endfor -%}
]
"version": "https://jsonfeed.org/version/1",
"title": "{{ title }}",
"home_page_url": "{{ globals.url }}",
"feed_url": "{{ permalink | absoluteUrl }}",
"description": "{{ globals.site_description }}",
"icon": "https://cdn.coryd.dev{{ globals.avatar }}?class=w200",
"author": {
"name": "{{ globals.site_name }}",
"url": "{{ globals.url }}",
"avatar": "https://cdn.coryd.dev{{ globals.avatar }}?class=w200"
},
"items": [
{%- assign entries = data -%}
{%- for entry in entries limit: 20 -%}
{
"id": "{{ entry.feed.url | encodeAmp }}",
"url": "{{ entry.feed.url | encodeAmp }}",
"title": "{{ entry.feed.title }}",
"date_published": "{{ entry.feed.date | stringToRFC3339 }}"
}{%- if forloop.last == false -%},{%- endif -%}
{%- endfor -%}
]
}

View file

@ -3,11 +3,11 @@
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<atom:link href="{{ permalink | absoluteUrl }}" rel="self" type="application/rss+xml" />
{%- assign entries = data | normalizeEntries: 20 -%}
{%- assign entries = data -%}
<title><![CDATA[{{ title }}]]></title>
<description><![CDATA[{{ globals.site_description }}]]></description>
<link>{{ permalink | absoluteUrl }}</link>
<lastBuildDate>{{ updated | stringToRFC822Date }}</lastBuildDate>
<lastBuildDate>{{ 'now' | date: "%a, %d %b %Y %H:%M:%S %z" }}</lastBuildDate>
<image>
<title><![CDATA[{{ title }}]]></title>
<link>{{ permalink | absoluteUrl }}</link>
@ -15,27 +15,28 @@
<width>144</width>
<height>144</height>
</image>
{% for entry in entries -%}
{% for entry in entries limit: 20 -%}
{%- assign entryFeed = entry.feed -%}
{%- assign rating = entry.rating -%}
{%- capture entryTitle -%}
{{ entry.title }}
{%- if entry.authors %} via {{ entry.authors.name }}{%- endif -%}
{{ entryFeed.title }}
{%- if entryFeed.artist and entryFeed.artist.name %} via {{ entryFeed.artist.name }}{%- endif -%}
{%- if rating %} ({{ rating }}){%- endif -%}
{%- endcapture -%}
{%- assign utm_parameters = "utm_source=rss&utm_medium=feed&utm_campaign=" | append: utm_campaign -%}
<item>
<title><![CDATA[{{ entryTitle }}]]></title>
{%- if utm_campaign -%}
<link>{{ entry.url | append: '?' | append: utm_parameters | encodeAmp }}</link>
<link>{{ entryFeed.url | append: '?' | append: utm_parameters | encodeAmp }}</link>
{%- else -%}
<link>{{ entry.url | encodeAmp }}</link>
<link>{{ entryFeed.url | encodeAmp }}</link>
{%- endif -%}
<pubDate>{{ entry.date | stringToRFC822Date }}</pubDate>
<guid isPermaLink="false">{{ entry.url | encodeAmp }}</guid>
{%- if entry.image -%}
<enclosure url="https://cdn.coryd.dev{{ entry.image }}?class=w800" type="image/jpeg" />
<pubDate>{{ entryFeed.date | stringToRFC822Date }}</pubDate>
<guid isPermaLink="false">{{ entryFeed.url | encodeAmp }}</guid>
{%- if entryFeed.image -%}
<enclosure url="https://cdn.coryd.dev{{ entryFeed.image }}?class=w800" type="image/jpeg" />
{%- endif -%}
<description>{{ entry.excerpt | escape }}</description>
<description><![CDATA[{{ entryFeed.description | escape | markdown }}]]></description>
</item>
{%- endfor %}
</channel>

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<atom:link href="{{ permalink | absoluteUrl }}" rel="self" type="application/rss+xml" />
{%- assign entries = data -%}
<title><![CDATA[{{ title }}]]></title>
<description><![CDATA[{{ globals.site_description }}]]></description>
<link>{{ permalink | absoluteUrl }}</link>
{% assign firstEntry = entries | first %}
<lastBuildDate>{{ 'now' | date: "%a, %d %b %Y %H:%M:%S %z" }}</lastBuildDate>
<image>
<title><![CDATA[{{ title }}]]></title>
<link>{{ permalink | absoluteUrl }}</link>
<url>{{ "https://cdn.coryd.dev" | append: globals.avatar | append: "?class=w200" }}</url>
<width>144</width>
<height>144</height>
</image>
{% for entry in entries limit: 20 -%}
{%- assign entrySyndication = entry.syndication -%}
<item>
<title><![CDATA[{{ entrySyndication.title }}]]></title>
<link>{{ entrySyndication.url | encodeAmp }}</link>
<pubDate>{{ entrySyndication.date | stringToRFC822Date }}</pubDate>
<guid isPermaLink="false">{{ entrySyndication.url | encodeAmp }}</guid>
<description><![CDATA[{{ entrySyndication.description | escape | markdown }}]]></description>
</item>
{%- endfor %}
</channel>
</rss>

View file

@ -1,4 +1,4 @@
---
permalink: /api/search
permalink: "/api/search"
---
{{ collections.searchIndex | json }}
{{ search | json }}

View file

@ -1,14 +0,0 @@
---
layout: null
eleventyExcludeFromCollections: true
permalink: "/feeds/album-releases.json"
---
{%- assign releases = albumReleases.current | reverse -%}
{% render "partials/feeds/json.liquid"
permalink:"/feeds/album-releases.json"
title:"Album releases / Cory Dransfeldt"
globals:globals
data:releases
updated:releases[0].releaseDate
appVersion:appVersion
%}

View file

@ -4,10 +4,9 @@ eleventyExcludeFromCollections: true
permalink: "/feeds/all.json"
---
{% render "partials/feeds/json.liquid"
permalink:"/feeds/all"
permalink:"/feeds/all.json"
title:"All activity / Cory Dransfeldt"
globals:globals
data:collections.allContent
updated:collections.allContent[0].date
data:activity
appVersion:appVersion
%}

View file

@ -3,13 +3,10 @@ layout: null
eleventyExcludeFromCollections: true
permalink: "/feeds/books.json"
---
{%- assign bookData = books.all | bookStatus: 'finished' -%}
{% render "partials/feeds/json.liquid"
permalink:"/feeds/books"
permalink:"/feeds/books.json"
title:"Books / Cory Dransfeldt"
globals:globals
data:bookData
updated:bookData[0].date
utm_campaign:"books_json_feed"
appVersion:appVersion
data:books.feed
utm_campaign:"books_feed"
%}

View file

@ -4,10 +4,8 @@ eleventyExcludeFromCollections: true
permalink: "/feeds/links.json"
---
{% render "partials/feeds/json.liquid"
permalink:"/feeds/links"
permalink:"/feeds/links.json"
title:"Links / Cory Dransfeldt"
globals:globals
data:links
updated:links[0].date
appVersion:appVersion
%}

View file

@ -4,11 +4,9 @@ eleventyExcludeFromCollections: true
permalink: "/feeds/movies.json"
---
{% render "partials/feeds/json.liquid"
permalink:"/feeds/movies"
permalink:"/feeds/movies.json"
title:"Movies / Cory Dransfeldt"
globals:globals
data:movies.recentlyWatched
updated:movies.recentlyWatched[0].lastWatched
utm_campaign:"movies_json_feed"
appVersion:appVersion
data:movies.feed
utm_campaign:"movies_feed"
%}

View file

@ -4,11 +4,9 @@ eleventyExcludeFromCollections: true
permalink: "/feeds/posts.json"
---
{% render "partials/feeds/json.liquid"
permalink:"/feeds/posts"
permalink:"/feeds/posts.json"
title:"Posts / Cory Dransfeldt"
globals:globals
data:posts
updated:posts[0].date
utm_campaign:"posts_json_feed"
appVersion:appVersion
utm_campaign:"posts_feed"
%}

View file

@ -1,13 +0,0 @@
---
layout: null
eleventyExcludeFromCollections: true
permalink: "/feeds/album-releases"
---
{%- assign releases = albumReleases.current | reverse -%}
{% render "partials/feeds/rss.liquid"
permalink:"/feeds/album-releases"
title:"Album releases / Cory Dransfeldt"
globals:globals
data:releases
updated:releases[0].releaseDate
%}

View file

@ -7,6 +7,5 @@ permalink: "/feeds/all"
permalink:"/feeds/all"
title:"All activity / Cory Dransfeldt"
globals:globals
data:collections.allContent
updated:collections.allContent[0].date
data:activity
%}

View file

@ -3,12 +3,10 @@ layout: null
eleventyExcludeFromCollections: true
permalink: "/feeds/books"
---
{%- assign bookData = books.all | bookStatus: 'finished' -%}
{% render "partials/feeds/rss.liquid"
permalink:"/feeds/books"
title:"Books / Cory Dransfeldt"
globals:globals
data:bookData
updated:bookData[0].date
data:books.feed
utm_campaign:"books_feed"
%}

View file

@ -8,5 +8,4 @@ permalink: "/feeds/links"
title:"Links / Cory Dransfeldt"
globals:globals
data:links
updated:links[0].date
%}

View file

@ -7,7 +7,6 @@ permalink: "/feeds/movies"
permalink:"/feeds/movies"
title:"Movies / Cory Dransfeldt"
globals:globals
data:movies.recentlyWatched
updated:movies.recentlyWatched[0].lastWatched
data:movies.feed
utm_campaign:"movies_feed"
%}

View file

@ -8,6 +8,5 @@ permalink: "/feeds/posts"
title:"Posts / Cory Dransfeldt"
globals:globals
data:posts
updated:posts[0].date
utm_campaign:"posts_feed"
%}

View file

@ -0,0 +1,11 @@
---
layout: null
eleventyExcludeFromCollections: true
permalink: "/feeds/syndication"
---
{% render "partials/feeds/syndication.rss.liquid"
permalink:"/feeds/syndication"
title:"Syndicated content / Cory Dransfeldt"
globals:globals
data:syndication
%}

View file

@ -5,12 +5,12 @@ eleventyExcludeFromCollections: true
---
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% for page in collections.siteMap %}
{% for page in sitemap -%}
<url>
<loc>{{ page.url }}</loc>
<lastmod>{{ page.date | date: '%Y-%m-%dT%H:%M:%S%:z' }}</lastmod>
<changefreq>{% if page.data.changeFreq %}{{ page.data.changeFreq }}{% else %}monthly{% endif %}</changefreq>
<priority>{% if page.data.priority %}{{ page.data.priority }}{% else %}0.5{% endif %}</priority>
<changefreq>monthly</changefreq>
<priority>0.5</priority>
</url>
{% endfor %}
</urlset>