-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatic blog indexing and archive pages
- Loading branch information
Showing
14 changed files
with
217 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* @template T | ||
* @typedef {import('@siteup/cli').PageFunction<T>} PageFunction | ||
*/ | ||
|
||
export const vars = { | ||
title: 'Breadcrum.net 2023 Blogs', | ||
layout: 'blog-auto-index' | ||
} | ||
|
||
/** | ||
* @type {PageFunction<{ | ||
* title: string | ||
* publishDate: string | ||
* }>} | ||
*/ | ||
export default async function blogIndex2023 () { | ||
return '' | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { html } from 'uland-isomorphic' | ||
import { dirname, basename } from 'node:path' | ||
|
||
/** | ||
* @template T | ||
* @typedef {import('@siteup/cli').PageFunction<T>} PageFunction | ||
*/ | ||
|
||
export const vars = { | ||
title: 'Breadcrum.net Blog', | ||
layout: 'blog-index' | ||
} | ||
|
||
/** | ||
* @type {PageFunction<{ | ||
* siteName: string, | ||
* siteDescription: string, | ||
* siteUrl: string, | ||
* authorName: string, | ||
* authorUrl: string, | ||
* authorImgUrl: string | ||
* layout: string, | ||
* publishDate: string | ||
* title: string | ||
* }>} | ||
*/ | ||
export default async function blogIndex2023 ({ | ||
pages, | ||
page | ||
}) { | ||
const blogPosts = pages | ||
.filter(page => page.vars.layout === 'article') | ||
// @ts-ignore | ||
.sort((a, b) => new Date(b.vars.publishDate) - new Date(a.vars.publishDate)) | ||
.slice(0, 50) | ||
|
||
const folderPages = pages.filter(folderPage => { | ||
const dir = dirname(folderPage.pageInfo.path) | ||
const path = page.path | ||
return dir === path | ||
}) | ||
|
||
return html` | ||
<ul class="blog-index-list"> | ||
${blogPosts.map(p => { | ||
const publishDate = p.vars.publishDate ? new Date(p.vars.publishDate) : null | ||
return html` | ||
<li class="blog-entry h-entry"> | ||
<a class="blog-entry-link u-url u-uid p-name" href="/${p.pageInfo.path}/">${p.vars.title}</a> | ||
${ | ||
publishDate | ||
? html`<time class="blog-entry-date dt-published" datetime="${publishDate.toISOString()}"> | ||
${publishDate.toISOString().split('T')[0]} | ||
</time>` | ||
: null | ||
} | ||
</li>` | ||
})} | ||
</ul> | ||
<footer class="blog-index-footer"> | ||
<h4>Archive</h4> | ||
<ul class="archive-list"> | ||
${folderPages.map(p => { | ||
return html`<li> | ||
<a href="/${p.pageInfo.path}/">${basename(p.pageInfo.path)}</a> | ||
</li>` | ||
})} | ||
<ul> | ||
</footer> | ||
` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.blog-index-footer { | ||
& .archive-list { | ||
padding-left: 0px; | ||
display: inline-flex; | ||
gap: 1em; | ||
list-style-type: none; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import './blog-index.layout.css'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { html } from 'uland-isomorphic' | ||
import { dirname } from 'node:path' | ||
|
||
/** | ||
* @template T | ||
* @typedef {import('@siteup/cli').LayoutFunction<T>} LayoutFunction | ||
*/ | ||
|
||
/** | ||
* @typedef {import('./blog-index.layout.js').BlogIndexVars} BlogIndexVars | ||
*/ | ||
|
||
/** | ||
* @typedef {BlogIndexVars} AutoBlogIndexVars | ||
*/ | ||
|
||
import blogIndexLayout from './blog-index.layout.js' | ||
|
||
/** @type {LayoutFunction<AutoBlogIndexVars>} */ | ||
export default function blogAutoIndexLayout (args) { | ||
const { children, ...rest } = args | ||
|
||
const folderPages = args.pages.filter(folderPage => { | ||
const dir = dirname(folderPage.pageInfo.path) | ||
const path = args.page.path | ||
return dir === path | ||
}).sort((a, b) => new Date(b.vars.publishDate) - new Date(a.vars.publishDate)) | ||
|
||
const wrappedChildren = html` | ||
<ul class="blog-index-list"> | ||
${folderPages.map(p => { | ||
const publishDate = p.vars.publishDate ? new Date(p.vars.publishDate) : null | ||
return html` | ||
<li class="blog-entry h-entry"> | ||
<a class="blog-entry-link u-url u-uid p-name" href="/${p.pageInfo.path}/">${p.vars.title}</a> | ||
${ | ||
publishDate | ||
? html`<time class="blog-entry-date dt-published" datetime="${publishDate.toISOString()}"> | ||
${publishDate.toISOString().split('T')[0]} | ||
</time>` | ||
: null | ||
} | ||
</li>` | ||
})} | ||
</ul> | ||
${typeof children === 'string' | ||
? html([children]) | ||
: children /* Support both uhtml and string children. Optional. */ | ||
} | ||
` | ||
|
||
return blogIndexLayout({ children: wrappedChildren, ...rest }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,17 @@ | ||
@import '../components/breadcrumb/index.css'; | ||
|
||
.blog-index-list { | ||
padding-left: 0px; | ||
|
||
& .blog-entry { | ||
width: 100%; | ||
display: inline-flex; | ||
justify-content: space-between; | ||
} | ||
& .blog-entry-link {} | ||
& .blog-entry-date { | ||
color: var(--accent-foreground); | ||
font-family: var(--font-code); | ||
flex-shrink: 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters