mirror of
https://github.com/kremalicious/blog.git
synced 2024-12-23 01:30:01 +01:00
refactor
This commit is contained in:
parent
be6af0993b
commit
684d835c9e
@ -47,90 +47,51 @@ exports.generatePostPages = (createPage, posts) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function generateIndexPages(createPage, length, slug, template) {
|
||||||
|
const numPages = Math.ceil(length / itemsPerPage)
|
||||||
|
|
||||||
|
Array.from({ length: numPages }).forEach((_, i) => {
|
||||||
|
const { prevPagePath, nextPagePath, path } = getPaginationData(
|
||||||
|
i,
|
||||||
|
numPages,
|
||||||
|
slug
|
||||||
|
)
|
||||||
|
|
||||||
|
createPage({
|
||||||
|
path,
|
||||||
|
component: template,
|
||||||
|
context: {
|
||||||
|
slug,
|
||||||
|
limit: itemsPerPage,
|
||||||
|
skip: i * itemsPerPage,
|
||||||
|
numPages: numPages,
|
||||||
|
currentPageNumber: i + 1,
|
||||||
|
prevPagePath,
|
||||||
|
nextPagePath
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create paginated archive pages
|
||||||
exports.generateArchivePages = (createPage, archiveLength) => {
|
exports.generateArchivePages = (createPage, archiveLength) => {
|
||||||
// Create paginated archive pages
|
generateIndexPages(createPage, archiveLength, `/archive/`, archiveTemplate)
|
||||||
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
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create paginated photos pages
|
||||||
exports.generatePhotosPages = (createPage, photosLength) => {
|
exports.generatePhotosPages = (createPage, photosLength) => {
|
||||||
// Create paginated photos pages
|
generateIndexPages(createPage, photosLength, `/photos/`, photosTemplate)
|
||||||
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
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create paginated tag pages
|
||||||
exports.generateTagPages = (createPage, tags) => {
|
exports.generateTagPages = (createPage, tags) => {
|
||||||
tags.forEach(({ tag, totalCount }) => {
|
tags.forEach(({ tag, totalCount }) => {
|
||||||
// Create paginated tag pages
|
generateIndexPages(
|
||||||
const numPages = Math.ceil(totalCount / itemsPerPage)
|
createPage,
|
||||||
const slug = `/archive/${tag}/`
|
totalCount,
|
||||||
|
`/archive/${tag}/`,
|
||||||
Array.from({ length: numPages }).forEach((_, i) => {
|
archiveTemplate
|
||||||
const { prevPagePath, nextPagePath, path } = getPaginationData(
|
)
|
||||||
i,
|
|
||||||
numPages,
|
|
||||||
slug
|
|
||||||
)
|
|
||||||
|
|
||||||
createPage({
|
|
||||||
path,
|
|
||||||
component: archiveTemplate,
|
|
||||||
context: {
|
|
||||||
tag,
|
|
||||||
slug,
|
|
||||||
limit: itemsPerPage,
|
|
||||||
skip: i * itemsPerPage,
|
|
||||||
numPages,
|
|
||||||
currentPageNumber: i + 1,
|
|
||||||
prevPagePath,
|
|
||||||
nextPagePath
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
src/components/molecules/PostDate.module.scss
Normal file
8
src/components/molecules/PostDate.module.scss
Normal 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;
|
||||||
|
}
|
19
src/components/molecules/PostDate.tsx
Normal file
19
src/components/molecules/PostDate.tsx
Normal 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>
|
||||||
|
)
|
||||||
|
}
|
@ -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>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
|
|
||||||
|
@ -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}>
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
|
@ -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>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user