feat: rejig tag page
This commit is contained in:
parent
29a2846eef
commit
9ff85a80af
3 changed files with 23 additions and 31 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "www-aaronjy-me",
|
"name": "www-aaronjy-me",
|
||||||
"version": "1.7.0.1",
|
"version": "1.7.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -30,7 +30,7 @@ function Article ({ attributes, html }) {
|
||||||
<Link href='./'>Back...</Link>
|
<Link href='./'>Back...</Link>
|
||||||
{attributes.pubdate && <p>{formatDate(attributes.pubdate)}</p>}
|
{attributes.pubdate && <p>{formatDate(attributes.pubdate)}</p>}
|
||||||
<div data-test='content' dangerouslySetInnerHTML={{ __html: html }} />
|
<div data-test='content' dangerouslySetInnerHTML={{ __html: html }} />
|
||||||
{attributes.tags && <p>Tags: {attributes.tags}</p>}
|
{attributes.tags && <p>Tags: {attributes.tags.join(', ')}</p>}
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -2,6 +2,7 @@ import DefaultLayout from '@/layouts/DefaultLayout/DefaultLayout'
|
||||||
import { getContentTags, getStaticEntries } from '@/lib/content'
|
import { getContentTags, getStaticEntries } from '@/lib/content'
|
||||||
import { NextSeo } from 'next-seo'
|
import { NextSeo } from 'next-seo'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
export const getStaticProps = () => ({
|
export const getStaticProps = () => ({
|
||||||
props: {
|
props: {
|
||||||
|
@ -13,8 +14,6 @@ export const getStaticProps = () => ({
|
||||||
export const Title = 'Tags'
|
export const Title = 'Tags'
|
||||||
|
|
||||||
export default function Tags ({ tags, postEntries }) {
|
export default function Tags ({ tags, postEntries }) {
|
||||||
const tagNames = Object.keys(tags).sort()
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DefaultLayout>
|
<DefaultLayout>
|
||||||
<NextSeo
|
<NextSeo
|
||||||
|
@ -29,35 +28,28 @@ export default function Tags ({ tags, postEntries }) {
|
||||||
<h1>{Title}</h1>
|
<h1>{Title}</h1>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
|
{Object.keys(tags).sort().map(tag => {
|
||||||
|
const posts = postEntries
|
||||||
|
.filter(p => p.attributes.tags.includes(tag))
|
||||||
|
.sort((a, b) => b.attributes.title > -a.attributes.title)
|
||||||
|
|
||||||
<table>
|
return (
|
||||||
<thead>
|
<React.Fragment key={tag}>
|
||||||
<tr>
|
<h2>{tag}</h2>
|
||||||
<th>Tag</th>
|
<ul>
|
||||||
<th>Posts</th>
|
{posts.map((post, _) => {
|
||||||
</tr>
|
return (
|
||||||
|
<li key={post.slug}>
|
||||||
</thead>
|
<Link href={`/writing/${post.slug}`}>{post.attributes.title}</Link>
|
||||||
<tbody>
|
</li>
|
||||||
{tagNames.map(tag => {
|
)
|
||||||
const posts = postEntries.filter(p => p.attributes.tags.includes(tag)).sort((a, b) => a.attributes.title > b.attributes.title ? 1 : -1)
|
})}
|
||||||
|
</ul>
|
||||||
return (
|
</React.Fragment>
|
||||||
<tr key={tag}>
|
)
|
||||||
<td>{tag} ({posts.length})</td>
|
})}
|
||||||
<td>
|
|
||||||
{posts && posts.map(post => {
|
|
||||||
return (
|
|
||||||
<div key={'tag-' + post.slug}><Link href={`/writing/${post.slug}`}>{post.attributes.title}</Link></div>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
</DefaultLayout>
|
</DefaultLayout>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue