From 44bf9b24a7793a8a25fd311b8264a67a36af850c Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Wed, 8 Jul 2020 01:31:03 +0200 Subject: [PATCH] prototype new frontpage structure --- gatsby/createPages.js | 10 +- ...{Posts.module.scss => Archive.module.scss} | 0 .../{Posts.test.tsx => Archive.test.tsx} | 6 +- .../templates/{Posts.tsx => Archive.tsx} | 7 +- src/components/templates/Post/Title.tsx | 16 +-- src/pages/index.module.scss | 4 + src/pages/index.tsx | 101 ++++++++++++++++++ 7 files changed, 125 insertions(+), 19 deletions(-) rename src/components/templates/{Posts.module.scss => Archive.module.scss} (100%) rename src/components/templates/{Posts.test.tsx => Archive.test.tsx} (89%) rename src/components/templates/{Posts.tsx => Archive.tsx} (94%) create mode 100644 src/pages/index.module.scss create mode 100644 src/pages/index.tsx diff --git a/gatsby/createPages.js b/gatsby/createPages.js index 9cd350e6..8071bf05 100644 --- a/gatsby/createPages.js +++ b/gatsby/createPages.js @@ -1,5 +1,5 @@ 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 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 slug = `/` + const slug = `/archive/` Array.from({ length: numPages }).forEach((_, i) => { const { prevPagePath, nextPagePath, path } = getPaginationData( @@ -58,7 +58,7 @@ exports.generatePostPages = (createPage, posts) => { createPage({ path, - component: postsTemplate, + component: archiveTemplate, context: { slug, limit: itemsPerPage, @@ -87,7 +87,7 @@ exports.generateTagPages = (createPage, tags) => { createPage({ path, - component: postsTemplate, + component: archiveTemplate, context: { tag, slug, diff --git a/src/components/templates/Posts.module.scss b/src/components/templates/Archive.module.scss similarity index 100% rename from src/components/templates/Posts.module.scss rename to src/components/templates/Archive.module.scss diff --git a/src/components/templates/Posts.test.tsx b/src/components/templates/Archive.test.tsx similarity index 89% rename from src/components/templates/Posts.test.tsx rename to src/components/templates/Archive.test.tsx index 176c60b0..0088983a 100644 --- a/src/components/templates/Posts.test.tsx +++ b/src/components/templates/Archive.test.tsx @@ -2,10 +2,10 @@ import React from 'react' import { render } from '@testing-library/react' import { createHistory, createMemorySource } from '@reach/router' -import Posts from './Posts' +import Archive from './Archive' import data from '../../../jest/__fixtures__/posts.json' -describe('Post', () => { +describe('Archive', () => { const history = createHistory(createMemorySource('/photos')) const pageContext = { @@ -17,7 +17,7 @@ describe('Post', () => { it('renders without crashing', () => { const { container } = render( - - {location.pathname === '/' && } {tag && (

# @@ -88,7 +86,7 @@ export default function Posts({ ) } -export const postsQuery = graphql` +export const archiveQuery = graphql` query($tag: String, $skip: Int, $limit: Int) { allMarkdownRemark( filter: { frontmatter: { tags: { eq: $tag } } } @@ -103,6 +101,7 @@ export const postsQuery = graphql` excerpt(pruneLength: 250) frontmatter { title + updated type linkurl image { diff --git a/src/components/templates/Post/Title.tsx b/src/components/templates/Post/Title.tsx index 7d5fde92..2b6e3fd9 100644 --- a/src/components/templates/Post/Title.tsx +++ b/src/components/templates/Post/Title.tsx @@ -16,7 +16,7 @@ export default function PostTitle({ slug?: string linkurl?: string title: string - date: string + date?: string updated?: string }): ReactElement { const linkHostname = linkurl ? new URL(linkurl).hostname : null @@ -39,12 +39,14 @@ export default function PostTitle({ ) : ( <>

{title}

-
- {updated && 'published '} -
+ {date && ( +
+ {updated && 'published '} +
+ )} ) } diff --git a/src/pages/index.module.scss b/src/pages/index.module.scss new file mode 100644 index 00000000..9693d8a1 --- /dev/null +++ b/src/pages/index.module.scss @@ -0,0 +1,4 @@ +@import 'variables'; + +.home { +} diff --git a/src/pages/index.tsx b/src/pages/index.tsx new file mode 100644 index 00000000..d254efdf --- /dev/null +++ b/src/pages/index.tsx @@ -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 ( + + + Latest Posts & Links +
+ Latest Photos +
+ ) +} + +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 + } + } + } + } + } +`