From f2f3dd652a545622419a75c6113f697d8c592691 Mon Sep 17 00:00:00 2001 From: Mark Teekman Date: Thu, 3 Nov 2022 22:11:14 +0100 Subject: [PATCH 1/7] Improved blog and posts (pagination, breadcrumbs, SEO). --- src/pages/blog.astro | 50 ------------- src/pages/blog/[...page].astro | 70 +++++++++++++++++++ .../{posts/[id].astro => blog/[post].astro} | 25 ++++++- 3 files changed, 93 insertions(+), 52 deletions(-) delete mode 100644 src/pages/blog.astro create mode 100644 src/pages/blog/[...page].astro rename src/pages/{posts/[id].astro => blog/[post].astro} (62%) diff --git a/src/pages/blog.astro b/src/pages/blog.astro deleted file mode 100644 index 82953b9..0000000 --- a/src/pages/blog.astro +++ /dev/null @@ -1,50 +0,0 @@ ---- -import DefaultLayout from '../layouts/DefaultLayout.astro' -import { Card } from 'accessible-astro-components' - -const response = await fetch('https://jsonplaceholder.typicode.com/posts') -const data = await response.json() ---- - - -
-
-

Blog


-

An example of a blog with dynamic content fetched from JSONPlaceholder using the title, body and userId. The Accessible Astro Card Component is used here to display al the posts.

-
-
-
-
-
    - {data.map((post) => ( -
  • - - {post.body} - -
  • - ))} -
-
-
-
- - \ No newline at end of file diff --git a/src/pages/blog/[...page].astro b/src/pages/blog/[...page].astro new file mode 100644 index 0000000..6f36304 --- /dev/null +++ b/src/pages/blog/[...page].astro @@ -0,0 +1,70 @@ +--- +import DefaultLayout from '../../layouts/DefaultLayout.astro' +import { Card, Pagination } from 'accessible-astro-components' + +export async function getStaticPaths({ paginate }) { + const response = await fetch('https://jsonplaceholder.typicode.com/posts') + const data = await response.json() + + return paginate(data, { pageSize: 6 }) +} + +const { page } = Astro.props +--- + + +
+
+

Blog


+

An example of a blog with dynamic content fetched from JSONPlaceholder using the title, body and userId. The Accessible Astro Card Component is used here to display al the posts.

+
+
+
+
+

Post {page.start + 1} through {page.end + 1} of {page.total} total posts

+
    + {page.data.map((post) => ( +
  • + + {post.body} + +
  • + ))} +
+
+ +
+
+
+
+ + \ No newline at end of file diff --git a/src/pages/posts/[id].astro b/src/pages/blog/[post].astro similarity index 62% rename from src/pages/posts/[id].astro rename to src/pages/blog/[post].astro index 52f56b2..ff6e216 100644 --- a/src/pages/posts/[id].astro +++ b/src/pages/blog/[post].astro @@ -1,12 +1,13 @@ --- import DefaultLayout from '../../layouts/DefaultLayout.astro' +import { Breadcrumbs, BreadcrumbsItem } from 'accessible-astro-components' export async function getStaticPaths() { const data = await fetch('https://jsonplaceholder.typicode.com/posts').then(response => response.json()) return data.map((post) => { return { - params: { id: post.id.toString() }, + params: { post: post.title.replaceAll(' ', '-').toLowerCase() }, props: { post } } }) @@ -15,7 +16,27 @@ export async function getStaticPaths() { const { post } = Astro.props --- - + +
+ + + + + +

{post.title}


From f93594f99f246692cc1a2307322b746317519d7a Mon Sep 17 00:00:00 2001 From: Mark Teekman Date: Thu, 3 Nov 2022 22:11:41 +0100 Subject: [PATCH 2/7] Fixed typo in the title of the 404 page. --- src/pages/404.astro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/404.astro b/src/pages/404.astro index 48c350e..b412871 100644 --- a/src/pages/404.astro +++ b/src/pages/404.astro @@ -2,7 +2,7 @@ import DefaultLayout from '../layouts/DefaultLayout.astro' --- - +

404


From 6e0a671fd3298dad5f9ad093222a0237e963df16 Mon Sep 17 00:00:00 2001 From: Mark Teekman Date: Thu, 3 Nov 2022 22:12:06 +0100 Subject: [PATCH 3/7] New SEO component `SiteMeta.astro`. --- src/components/SiteMeta.astro | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/components/SiteMeta.astro diff --git a/src/components/SiteMeta.astro b/src/components/SiteMeta.astro new file mode 100644 index 0000000..7a2f5d5 --- /dev/null +++ b/src/components/SiteMeta.astro @@ -0,0 +1,20 @@ +--- +const { + title, + description, + url, + image, +} = Astro.props + +let subtitle = 'Accessible Astro Starter' +--- + + + + + + + + + +{title} - {subtitle} From 541425c2b5c36ef7b061d3207f9fc1328bca43e8 Mon Sep 17 00:00:00 2001 From: Mark Teekman Date: Thu, 3 Nov 2022 22:15:53 +0100 Subject: [PATCH 4/7] Moved theming styles to `DefaultLayout.astro` and added the new `SiteMeta.astro` component. --- src/assets/scss/base/_root.scss | 19 ------------ src/layouts/DefaultLayout.astro | 53 ++++++++++++++++++++++++++------- 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/src/assets/scss/base/_root.scss b/src/assets/scss/base/_root.scss index b32c8ad..f4e99e1 100644 --- a/src/assets/scss/base/_root.scss +++ b/src/assets/scss/base/_root.scss @@ -10,23 +10,4 @@ --#{$color}-#{$shade}: #{$value}; } } - --radius-small: 3px; - --radius-large: 6px; - --gap-default: 2rem; - --font-measure: 70ch; - --font-family-default: "Open Sans", sans-serif; - --font-family-special: "Open Sans", sans-serif; - --font-color: var(--neutral-900); - --action-color: var(--secondary-500); - --background: var(--neutral-100); - --primary-background: var(--primary-100); - --neutral-background: var(--neutral-200); -} - -.darkmode { - --font-color: var(--neutral-100); - --action-color: var(--secondary-100); - --background: var(--neutral-800); - --primary-background: var(--primary-500); - --neutral-background: var(--neutral-900); } diff --git a/src/layouts/DefaultLayout.astro b/src/layouts/DefaultLayout.astro index a504aa1..7f7d365 100644 --- a/src/layouts/DefaultLayout.astro +++ b/src/layouts/DefaultLayout.astro @@ -1,10 +1,15 @@ --- import '../assets/scss/globals.scss' +import SiteMeta from '../components/SiteMeta.astro' import Header from '../components/Header.astro' import Footer from '../components/Footer.astro' -const {title} = Astro.props -let subtitle = 'Accessible Astro Starter' +const { + title = 'Astro', + description = 'A starter project with accessible features using Astro static site builder. Contains accessible landmarks, skip links, a dark mode color scheme, better focus outline and keyboard menu navigation.', + url, + image = '/social-preview-image.png', +} = Astro.props --- @@ -21,15 +26,16 @@ let subtitle = 'Accessible Astro Starter' - - - - - - - - - {title} - {subtitle} +
@@ -41,6 +47,31 @@ let subtitle = 'Accessible Astro Starter'