mirror of
https://github.com/kremalicious/blog.git
synced 2025-02-14 21:10:25 +01:00
prototype new frontpage structure
This commit is contained in:
parent
de17f9cd63
commit
44bf9b24a7
@ -1,5 +1,5 @@
|
|||||||
const path = require('path')
|
const path = require('path')
|
||||||
const postsTemplate = path.resolve('src/components/templates/Posts.tsx')
|
const archiveTemplate = path.resolve('src/components/templates/Posts.tsx')
|
||||||
const { itemsPerPage } = require('../config')
|
const { itemsPerPage } = require('../config')
|
||||||
|
|
||||||
const redirects = [
|
const redirects = [
|
||||||
@ -45,9 +45,9 @@ exports.generatePostPages = (createPage, posts) => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// Create paginated Blog index pages
|
// Create paginated Blog archive pages
|
||||||
const numPages = Math.ceil(posts.length / itemsPerPage)
|
const numPages = Math.ceil(posts.length / itemsPerPage)
|
||||||
const slug = `/`
|
const slug = `/archive/`
|
||||||
|
|
||||||
Array.from({ length: numPages }).forEach((_, i) => {
|
Array.from({ length: numPages }).forEach((_, i) => {
|
||||||
const { prevPagePath, nextPagePath, path } = getPaginationData(
|
const { prevPagePath, nextPagePath, path } = getPaginationData(
|
||||||
@ -58,7 +58,7 @@ exports.generatePostPages = (createPage, posts) => {
|
|||||||
|
|
||||||
createPage({
|
createPage({
|
||||||
path,
|
path,
|
||||||
component: postsTemplate,
|
component: archiveTemplate,
|
||||||
context: {
|
context: {
|
||||||
slug,
|
slug,
|
||||||
limit: itemsPerPage,
|
limit: itemsPerPage,
|
||||||
@ -87,7 +87,7 @@ exports.generateTagPages = (createPage, tags) => {
|
|||||||
|
|
||||||
createPage({
|
createPage({
|
||||||
path,
|
path,
|
||||||
component: postsTemplate,
|
component: archiveTemplate,
|
||||||
context: {
|
context: {
|
||||||
tag,
|
tag,
|
||||||
slug,
|
slug,
|
||||||
|
@ -2,10 +2,10 @@ import React from 'react'
|
|||||||
import { render } from '@testing-library/react'
|
import { render } from '@testing-library/react'
|
||||||
import { createHistory, createMemorySource } from '@reach/router'
|
import { createHistory, createMemorySource } from '@reach/router'
|
||||||
|
|
||||||
import Posts from './Posts'
|
import Archive from './Archive'
|
||||||
import data from '../../../jest/__fixtures__/posts.json'
|
import data from '../../../jest/__fixtures__/posts.json'
|
||||||
|
|
||||||
describe('Post', () => {
|
describe('Archive', () => {
|
||||||
const history = createHistory(createMemorySource('/photos'))
|
const history = createHistory(createMemorySource('/photos'))
|
||||||
|
|
||||||
const pageContext = {
|
const pageContext = {
|
||||||
@ -17,7 +17,7 @@ describe('Post', () => {
|
|||||||
|
|
||||||
it('renders without crashing', () => {
|
it('renders without crashing', () => {
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<Posts
|
<Archive
|
||||||
data={data}
|
data={data}
|
||||||
pageContext={pageContext}
|
pageContext={pageContext}
|
||||||
location={history.location}
|
location={history.location}
|
@ -2,7 +2,6 @@ import React, { ReactElement } from 'react'
|
|||||||
import { Link, graphql } from 'gatsby'
|
import { Link, graphql } from 'gatsby'
|
||||||
import { Post } from '../../@types/Post'
|
import { Post } from '../../@types/Post'
|
||||||
import Pagination from '../molecules/Pagination'
|
import Pagination from '../molecules/Pagination'
|
||||||
import Featured from '../molecules/Featured'
|
|
||||||
import PostTitle from './Post/Title'
|
import PostTitle from './Post/Title'
|
||||||
import PostLead from './Post/Lead'
|
import PostLead from './Post/Lead'
|
||||||
import PostContent from './Post/Content'
|
import PostContent from './Post/Content'
|
||||||
@ -12,7 +11,7 @@ import SEO from '../atoms/SEO'
|
|||||||
import styles from './Posts.module.scss'
|
import styles from './Posts.module.scss'
|
||||||
import { Image } from '../atoms/Image'
|
import { Image } from '../atoms/Image'
|
||||||
|
|
||||||
export default function Posts({
|
export default function Archive({
|
||||||
data,
|
data,
|
||||||
location,
|
location,
|
||||||
pageContext
|
pageContext
|
||||||
@ -70,7 +69,6 @@ export default function Posts({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SEO />
|
<SEO />
|
||||||
{location.pathname === '/' && <Featured />}
|
|
||||||
{tag && (
|
{tag && (
|
||||||
<h1 className={styles.archivetitle}>
|
<h1 className={styles.archivetitle}>
|
||||||
<span>#</span>
|
<span>#</span>
|
||||||
@ -88,7 +86,7 @@ export default function Posts({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const postsQuery = graphql`
|
export const archiveQuery = graphql`
|
||||||
query($tag: String, $skip: Int, $limit: Int) {
|
query($tag: String, $skip: Int, $limit: Int) {
|
||||||
allMarkdownRemark(
|
allMarkdownRemark(
|
||||||
filter: { frontmatter: { tags: { eq: $tag } } }
|
filter: { frontmatter: { tags: { eq: $tag } } }
|
||||||
@ -103,6 +101,7 @@ export const postsQuery = graphql`
|
|||||||
excerpt(pruneLength: 250)
|
excerpt(pruneLength: 250)
|
||||||
frontmatter {
|
frontmatter {
|
||||||
title
|
title
|
||||||
|
updated
|
||||||
type
|
type
|
||||||
linkurl
|
linkurl
|
||||||
image {
|
image {
|
@ -16,7 +16,7 @@ export default function PostTitle({
|
|||||||
slug?: string
|
slug?: string
|
||||||
linkurl?: string
|
linkurl?: string
|
||||||
title: string
|
title: string
|
||||||
date: string
|
date?: string
|
||||||
updated?: string
|
updated?: string
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const linkHostname = linkurl ? new URL(linkurl).hostname : null
|
const linkHostname = linkurl ? new URL(linkurl).hostname : null
|
||||||
@ -39,12 +39,14 @@ export default function PostTitle({
|
|||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<h1 className={styles.hentry__title}>{title}</h1>
|
<h1 className={styles.hentry__title}>{title}</h1>
|
||||||
|
{date && (
|
||||||
<div className={styles.time}>
|
<div className={styles.time}>
|
||||||
{updated && 'published '}
|
{updated && 'published '}
|
||||||
<Time date={date} />
|
<Time date={date} />
|
||||||
{updated && ' • updated '}
|
{updated && ' • updated '}
|
||||||
{updated && <Time date={updated} />}
|
{updated && <Time date={updated} />}
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
4
src/pages/index.module.scss
Normal file
4
src/pages/index.module.scss
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
@import 'variables';
|
||||||
|
|
||||||
|
.home {
|
||||||
|
}
|
101
src/pages/index.tsx
Normal file
101
src/pages/index.tsx
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
import React, { ReactElement } from 'react'
|
||||||
|
import { graphql, Link } from 'gatsby'
|
||||||
|
import Page from '../components/templates/Page'
|
||||||
|
import { Post } from '../@types/Post'
|
||||||
|
import { Image } from '../components/atoms/Image'
|
||||||
|
import styles from './index.module.scss'
|
||||||
|
import Featured from '../components/molecules/Featured'
|
||||||
|
|
||||||
|
const page = {
|
||||||
|
frontmatter: {
|
||||||
|
title: 'home',
|
||||||
|
description: 'Blog of designer & developer Matthias Kretschmann.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Home({
|
||||||
|
data,
|
||||||
|
location
|
||||||
|
}: {
|
||||||
|
data: any
|
||||||
|
location: Location
|
||||||
|
}): ReactElement {
|
||||||
|
return (
|
||||||
|
<Page
|
||||||
|
title={page.frontmatter.title}
|
||||||
|
post={page}
|
||||||
|
location={location}
|
||||||
|
section={styles.home}
|
||||||
|
>
|
||||||
|
<Featured />
|
||||||
|
Latest Posts & Links
|
||||||
|
<br />
|
||||||
|
Latest Photos
|
||||||
|
</Page>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const homeQuery = graphql`
|
||||||
|
query {
|
||||||
|
latestPosts: allMarkdownRemark(
|
||||||
|
filter: { frontmatter: { type: { eq: "post" } } }
|
||||||
|
sort: { order: DESC, fields: [fields___date] }
|
||||||
|
limit: 5
|
||||||
|
) {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
frontmatter {
|
||||||
|
title
|
||||||
|
type
|
||||||
|
image {
|
||||||
|
childImageSharp {
|
||||||
|
fluid(
|
||||||
|
maxWidth: 400
|
||||||
|
maxHeight: 400
|
||||||
|
quality: 85
|
||||||
|
cropFocus: CENTER
|
||||||
|
) {
|
||||||
|
...GatsbyImageSharpFluid_withWebp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fields {
|
||||||
|
slug
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
latestPhotos: allMarkdownRemark(
|
||||||
|
filter: { frontmatter: { type: { eq: "photo" } } }
|
||||||
|
sort: { order: DESC, fields: [fields___date] }
|
||||||
|
limit: 10
|
||||||
|
) {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
frontmatter {
|
||||||
|
title
|
||||||
|
type
|
||||||
|
image {
|
||||||
|
childImageSharp {
|
||||||
|
fluid(
|
||||||
|
maxWidth: 400
|
||||||
|
maxHeight: 400
|
||||||
|
quality: 85
|
||||||
|
cropFocus: CENTER
|
||||||
|
) {
|
||||||
|
...GatsbyImageSharpFluid_withWebp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fields {
|
||||||
|
slug
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
Loading…
Reference in New Issue
Block a user