1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-12-23 01:30:01 +01:00
This commit is contained in:
Matthias Kretschmann 2021-03-01 00:03:39 +01:00
parent be6af0993b
commit 684d835c9e
Signed by: m
GPG Key ID: 606EEEF3C479A91F
8 changed files with 71 additions and 120 deletions

View File

@ -47,67 +47,8 @@ exports.generatePostPages = (createPage, posts) => {
}) })
} }
exports.generateArchivePages = (createPage, archiveLength) => { function generateIndexPages(createPage, length, slug, template) {
// Create paginated archive pages const numPages = Math.ceil(length / itemsPerPage)
const numPagesArchive = Math.ceil(archiveLength / itemsPerPage)
const slugArchive = `/archive/`
Array.from({ length: numPagesArchive }).forEach((_, i) => {
const { prevPagePath, nextPagePath, path } = getPaginationData(
i,
numPagesArchive,
slugArchive
)
createPage({
path,
component: archiveTemplate,
context: {
slug: slugArchive,
limit: itemsPerPage,
skip: i * itemsPerPage,
numPages: numPagesArchive,
currentPageNumber: i + 1,
prevPagePath,
nextPagePath
}
})
})
}
exports.generatePhotosPages = (createPage, photosLength) => {
// Create paginated photos pages
const numPagesPhotos = Math.ceil(photosLength / itemsPerPage)
const slugPhotos = `/photos/`
Array.from({ length: numPagesPhotos }).forEach((_, i) => {
const { prevPagePath, nextPagePath, path } = getPaginationData(
i,
numPagesPhotos,
slugPhotos
)
createPage({
path,
component: photosTemplate,
context: {
slug: slugPhotos,
limit: itemsPerPage,
skip: i * itemsPerPage,
numPages: numPagesPhotos,
currentPageNumber: i + 1,
prevPagePath,
nextPagePath
}
})
})
}
exports.generateTagPages = (createPage, tags) => {
tags.forEach(({ tag, totalCount }) => {
// Create paginated tag pages
const numPages = Math.ceil(totalCount / itemsPerPage)
const slug = `/archive/${tag}/`
Array.from({ length: numPages }).forEach((_, i) => { Array.from({ length: numPages }).forEach((_, i) => {
const { prevPagePath, nextPagePath, path } = getPaginationData( const { prevPagePath, nextPagePath, path } = getPaginationData(
@ -118,19 +59,39 @@ exports.generateTagPages = (createPage, tags) => {
createPage({ createPage({
path, path,
component: archiveTemplate, component: template,
context: { context: {
tag,
slug, slug,
limit: itemsPerPage, limit: itemsPerPage,
skip: i * itemsPerPage, skip: i * itemsPerPage,
numPages, numPages: numPages,
currentPageNumber: i + 1, currentPageNumber: i + 1,
prevPagePath, prevPagePath,
nextPagePath nextPagePath
} }
}) })
}) })
}
// Create paginated archive pages
exports.generateArchivePages = (createPage, archiveLength) => {
generateIndexPages(createPage, archiveLength, `/archive/`, archiveTemplate)
}
// Create paginated photos pages
exports.generatePhotosPages = (createPage, photosLength) => {
generateIndexPages(createPage, photosLength, `/photos/`, photosTemplate)
}
// Create paginated tag pages
exports.generateTagPages = (createPage, tags) => {
tags.forEach(({ tag, totalCount }) => {
generateIndexPages(
createPage,
totalCount,
`/archive/${tag}/`,
archiveTemplate
)
}) })
} }

View File

@ -0,0 +1,8 @@
@import 'variables';
.time {
font-style: italic;
font-size: $font-size-small;
color: $text-color-light;
margin-bottom: $spacer / $line-height;
}

View File

@ -0,0 +1,19 @@
import React, { ReactElement } from 'react'
import Time from '../atoms/Time'
import styles from './PostDate.module.scss'
export default function PostDate({
date,
updated
}: {
date: string
updated?: string
}): ReactElement {
return (
<div className={styles.time}>
<Time date={date} />
{updated && ' • updated '}
{updated && <Time date={updated} />}
</div>
)
}

View File

@ -5,6 +5,7 @@ import { Post } from '../../@types/Post'
import PostTitle from '../templates/Post/Title' import PostTitle from '../templates/Post/Title'
import styles from './PostTeaser.module.scss' import styles from './PostTeaser.module.scss'
import Time from '../atoms/Time' import Time from '../atoms/Time'
import PostDate from './PostDate'
export const postTeaserQuery = graphql` export const postTeaserQuery = graphql`
fragment PostTeaser on MarkdownRemark { fragment PostTeaser on MarkdownRemark {
@ -58,13 +59,7 @@ export default function PostTeaser({
)} )}
<PostTitle slug={slug} title={title} className={styles.title} /> <PostTitle slug={slug} title={title} className={styles.title} />
{date && !hideDate && ( {date && !hideDate && <PostDate date={date} updated={updated} />}
<div className={styles.time}>
<Time date={date} />
{updated && ' • updated '}
{updated && <Time date={updated} />}
</div>
)}
</Link> </Link>
) )
} }

View File

@ -7,32 +7,18 @@
font-size: $font-size-small; font-size: $font-size-small;
margin-top: $spacer * 2; margin-top: $spacer * 2;
color: $brand-grey-light; color: $brand-grey-light;
}
.byline,
.time,
.tags,
.categories {
text-align: center; text-align: center;
} }
.byline,
.time {
font-style: italic;
}
.byline { .byline {
margin-bottom: 0; margin-bottom: 0;
font-style: italic;
} }
.by { .by {
display: block; display: block;
} }
.time {
margin-bottom: $spacer * 2;
}
// Types & Tags // Types & Tags
///////////////////////////////////// /////////////////////////////////////

View File

@ -1,12 +1,12 @@
import React, { ReactElement } from 'react' import React, { ReactElement } from 'react'
import { Link } from 'gatsby' import { Link } from 'gatsby'
import slugify from 'slugify' import slugify from 'slugify'
import Time from '../../atoms/Time'
import Tag from '../../atoms/Tag' import Tag from '../../atoms/Tag'
import { useSiteMetadata } from '../../../hooks/use-site-metadata' import { useSiteMetadata } from '../../../hooks/use-site-metadata'
import styles from './Meta.module.scss' import styles from './Meta.module.scss'
import { Post } from '../../../@types/Post' import { Post } from '../../../@types/Post'
import shortid from 'shortid' import shortid from 'shortid'
import PostDate from '../../molecules/PostDate'
export default function PostMeta({ post }: { post: Post }): ReactElement { export default function PostMeta({ post }: { post: Post }): ReactElement {
const siteMeta = useSiteMetadata() const siteMeta = useSiteMetadata()
@ -22,12 +22,7 @@ export default function PostMeta({ post }: { post: Post }): ReactElement {
</a> </a>
</div> </div>
<div className={styles.time}> <PostDate date={date} updated={updated} />
{updated && 'published '}
<Time date={date} />
{updated && ' • updated '}
{updated && <Time date={updated} />}
</div>
{type && type === 'photo' && ( {type && type === 'photo' && (
<div className={styles.type}> <div className={styles.type}>

View File

@ -32,10 +32,3 @@
margin-top: -($spacer); margin-top: -($spacer);
margin-bottom: $spacer; margin-bottom: $spacer;
} }
.time {
font-style: italic;
font-size: $font-size-small;
color: $text-color-light;
margin-bottom: $spacer / $line-height;
}

View File

@ -2,6 +2,7 @@ import React, { ReactElement } from 'react'
import styles from './Title.module.scss' import styles from './Title.module.scss'
import Icon from '../../atoms/Icon' import Icon from '../../atoms/Icon'
import Time from '../../atoms/Time' import Time from '../../atoms/Time'
import PostDate from '../../molecules/PostDate'
export default function PostTitle({ export default function PostTitle({
slug, slug,
@ -42,14 +43,7 @@ export default function PostTitle({
<h1 className={`${styles.hentry__title} ${className && className}`}> <h1 className={`${styles.hentry__title} ${className && className}`}>
{title} {title}
</h1> </h1>
{date && ( {date && <PostDate date={date} updated={updated} />}
<div className={styles.time}>
{updated && 'published '}
<Time date={date} />
{updated && ' • updated '}
{updated && <Time date={updated} />}
</div>
)}
</> </>
) )
} }