feat: split out dividers; proper block sorting

This commit is contained in:
Cory Dransfeldt 2024-07-14 21:17:17 -07:00
parent 4b908fc3df
commit 1a6e250875
No known key found for this signature in database
5 changed files with 13 additions and 8 deletions

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "20.5.0", "version": "20.6.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "coryd.dev", "name": "coryd.dev",
"version": "20.5.0", "version": "20.6.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@cdransf/api-text": "^1.4.0", "@cdransf/api-text": "^1.4.0",

View file

@ -1,6 +1,6 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "20.5.0", "version": "20.6.0",
"description": "The source for my personal site. Built using 11ty.", "description": "The source for my personal site. Built using 11ty.",
"type": "module", "type": "module",
"scripts": { "scripts": {

View file

@ -24,7 +24,7 @@ const fetchBlockData = async (collection, itemId) => {
const fetchBlocksForPage = async (pageId) => { const fetchBlocksForPage = async (pageId) => {
const { data, error } = await supabase const { data, error } = await supabase
.from('pages_blocks') .from('pages_blocks')
.select('collection, item') .select('collection, item, sort')
.eq('pages_id', pageId) .eq('pages_id', pageId)
if (error) { if (error) {
@ -37,11 +37,12 @@ const fetchBlocksForPage = async (pageId) => {
return { return {
type: block['collection'], type: block['collection'],
sort: block['sort'],
...blockData ...blockData
} }
})) }))
return blocks return blocks.sort((a, b) => a.sort - b.sort)
} }
const fetchAllPages = async () => { const fetchAllPages = async () => {

View file

@ -38,7 +38,7 @@ const fetchTagsForPost = async (postId) => {
const fetchBlocksForPost = async (postId) => { const fetchBlocksForPost = async (postId) => {
const { data, error } = await supabase const { data, error } = await supabase
.from('posts_blocks') .from('posts_blocks')
.select('collection, item') .select('collection, item, sort')
.eq('posts_id', postId) .eq('posts_id', postId)
if (error) { if (error) {
@ -48,8 +48,10 @@ const fetchBlocksForPost = async (postId) => {
const blocks = await Promise.all(data.map(async block => { const blocks = await Promise.all(data.map(async block => {
const blockData = await fetchBlockData(block.collection, block.item) const blockData = await fetchBlockData(block.collection, block.item)
return { return {
type: block.collection, type: block['collection'],
sort: block['sort'],
...blockData ...blockData
} }
})) }))

View file

@ -11,7 +11,9 @@
{% render "partials/blocks/hero.liquid", image:block.image.filename_disk, alt:block.alt_text %} {% render "partials/blocks/hero.liquid", image:block.image.filename_disk, alt:block.alt_text %}
{% elsif block.type == 'markdown' %} {% elsif block.type == 'markdown' %}
{{ block.text | markdown }} {{ block.text | markdown }}
{% elsif block.type == 'divider' %}
{{ block.markup | markdown }}
{% elsif block.type == 'addon_links' %} {% elsif block.type == 'addon_links' %}
<hr />{% render "partials/widgets/addon-links.liquid", popularPosts:collections.popularPosts, links:links %} {% render "partials/widgets/addon-links.liquid", popularPosts:collections.popularPosts, links:links %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}