Skip to content

Commit

Permalink
Add blog index and archive pages
Browse files Browse the repository at this point in the history
Automatic blog indexing and archive pages
  • Loading branch information
bcomnes committed Nov 6, 2023
1 parent fcb6174 commit f116b59
Show file tree
Hide file tree
Showing 14 changed files with 217 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@fastify/swagger-ui": "^1.3.0",
"@mozilla/readability": "^0.4.2",
"@nearform/sql": "^1.5.0",
"@siteup/cli": "^4.0.1",
"@siteup/cli": "^5.0.0",
"abstract-cache-redis": "^2.0.0",
"classnames": "^2.3.1",
"clean-deep": "^3.4.0",
Expand Down
8 changes: 0 additions & 8 deletions web/blog/2023/README.md

This file was deleted.

19 changes: 19 additions & 0 deletions web/blog/2023/page.js
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 ''
}
9 changes: 0 additions & 9 deletions web/blog/README.md

This file was deleted.

71 changes: 71 additions & 0 deletions web/blog/page.js
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>
`
}
8 changes: 8 additions & 0 deletions web/blog/style.css
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;
}
}
2 changes: 1 addition & 1 deletion web/components/footer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const footer = Component(({
<a href="/docs/">docs</a>
</div>
<div>
<a href="/blog/2023">blog</a>
<a href="/blog/">blog</a>
</div>
<div>
<a href="/docs/social/">@breadcrum</a>
Expand Down
8 changes: 8 additions & 0 deletions web/layouts/article.layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@
border-radius: 50%;
padding: 4px;
}

& .date-time {
font-family: var(--system-mono);
}

& .blog-footer {
color: var(--accent-foreground);
}
}
10 changes: 4 additions & 6 deletions web/layouts/article.layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function articleLayout (args) {
</address>
${vars.publishDate
? html`
<time class="dt-published" itemprop="datePublished" datetime="${vars.publishDate}">
<time class="date-time dt-published" itemprop="datePublished" datetime="${vars.publishDate}">
<a href="#" class="u-url">
${(new Date(vars.publishDate)).toLocaleString()}
</a>
Expand All @@ -51,11 +51,9 @@ export default function articleLayout (args) {
}
</section>
<!--
<footer>
<p>Footer notes or related info here...</p>
</footer>
-->
<footer class="blog-footer">
<p>Wan't to follow along for future updates? Follow our <a href="/docs/social/">socials and feeds</a>!</p>
</footer>
</article>
${breadcrumb({ pathSegments })}
`
Expand Down
1 change: 1 addition & 0 deletions web/layouts/blog-auto-index.layout.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import './blog-index.layout.css';
53 changes: 53 additions & 0 deletions web/layouts/blog-auto-index.layout.js
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 })
}
16 changes: 16 additions & 0 deletions web/layouts/blog-index.layout.css
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;
}
}
25 changes: 21 additions & 4 deletions web/layouts/blog-index.layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,38 @@ import { html } from 'uland-isomorphic'
import { sep } from 'node:path'
import { breadcrumb } from '../components/breadcrumb/index.js'

/**
* @template T
* @typedef {import('@siteup/cli').LayoutFunction<T>} LayoutFunction
*/

/**
* @typedef {import('./root.layout.js').RootLayoutVars} RootLayoutVars
*/

/**
* @typedef {RootLayoutVars & {
* title: string,
* publishDate: string,
* [key: string]: any
* }} BlogIndexVars
*/

import defaultRootLayout from './root.layout.js'

/** @type {LayoutFunction<BlogIndexVars>} */
export default function blogIndexLayout (args) {
const { children, ...rest } = args
const page = rest.page
const vars = rest.vars
const pathSegments = page.path.split(sep)
const pathSegments = args.page.path.split(sep)
const wrappedChildren = html`
${breadcrumb({ pathSegments })}
<h1>${vars.title}</h1>
<h1>${args.vars.title}</h1>
${typeof children === 'string'
? html([children])
: children /* Support both uhtml and string children. Optional. */
}
`

// @ts-ignore
return defaultRootLayout({ children: wrappedChildren, ...rest })
}
14 changes: 14 additions & 0 deletions web/layouts/root.layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ If you need to render components inside, you need attatch them in the global cli
*/

/**
* @template T
* @typedef {import('@siteup/cli').LayoutFunction<T>} LayoutFunction
*/

/**
* @typedef {{
* title: string,
* siteName: string,
* [key: string]: any
* }} RootLayoutVars
*/

/** @type {LayoutFunction<RootLayoutVars>} */
export default function defaultRootLayout ({
vars: {
title,
Expand Down

0 comments on commit f116b59

Please sign in to comment.