Skip to content

Commit

Permalink
[Closes #17] Fix undefined title on markdown pages
Browse files Browse the repository at this point in the history
Use the frontmatter when a markdown page is rendered with BaseLayout.astro.
Don't render an og:image tag when the URL isn't available.
Add a description to the About page.
  • Loading branch information
fwextensions committed Sep 30, 2024
1 parent 46878de commit 482fc6f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ A quick migration of the existing site content into a lightly-styled Astro build

## ✅ To do

- [ ] Compress HTML in build
- [ ] Set `base` tag by looking at the current domain name? Different configs?
- [ ] Restore dark mode when some text colors are fixed
- [ ] Add more interesting header fonts
- [X] Add SEO metadata to all pages
- [X] Fix favicon
- [X] Clean up jekyll code from old posts
- [X] Always show the first image in a blog post as the thumbnail
- [X] Don't show the image key in the frontmatter at the top of the post if it's used within the post
- [X] Make nav bar responsive on narrow screens
- [ ] Compress HTML in build
- [X] Set or improve blog descriptions
- [X] Replace img with Image in post markdown
- [ ] Restore dark mode when some text colors are fixed
- [ ] Add more interesting header fonts


## 🧞 Commands
Expand Down
6 changes: 4 additions & 2 deletions src/components/Metadata.astro
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ const tags = Object.entries(meta)
const ogTags = Object.entries({
title,
url,
// make sure the image metadata is an absolute URL, not just a relative path
image: new URL(image, import.meta.env.SITE),
// make sure the image metadata is an absolute URL, not just a relative path,
// and only include the key if it's truthy, so we don't include an `undefined`
// og:image tag
image: image && new URL(image as string, import.meta.env.SITE),
...meta
})
.map(([key, value]) => value ? ogMetaTag(key, value) : null)
Expand Down
15 changes: 13 additions & 2 deletions src/layouts/BaseLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,30 @@ import Page from "@/layouts/Page.astro";
import HeaderNav from "@/components/HeaderNav.astro";
import FooterNav from "@/components/FooterNav.astro";
import type { MetadataProp } from "@/components/Metadata.astro";
import type { MarkdownContent } from "astro";
interface Props {
title: string;
header?: string;
meta?: MetadataProp;
frontmatter?: MarkdownContent;
}
const { title, header = title, meta } = Astro.props;
const { frontmatter, title = frontmatter?.title, header = title, meta } = Astro.props;
let pageMeta = meta;
if (frontmatter && !meta?.description) {
// there's frontmatter, which means we're laying out a markdown file, so make
// sure there's metadata for the page, and copy any description from the
// markdown file
pageMeta ??= {};
pageMeta.description = frontmatter.description;
}
---

<Page
title={title}
meta={meta}
meta={pageMeta}
>
<HeaderNav />
<main class="container">
Expand Down
2 changes: 1 addition & 1 deletion src/pages/about/code-of-conduct.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: "@/layouts/BaseLayout.astro"
title: Code of Conduct
description: Code of Conduct
description: This Code of Conduct contains not just statements of belief, but principles that we collectively enact. We are dedicated to upholding them, and to ensuring that all members of our community respect them.
---

# SF Civic Tech is a space for everyone.
Expand Down
9 changes: 8 additions & 1 deletion src/pages/about/index.astro
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
---
import BaseLayout from "@/layouts/BaseLayout.astro";
import TeamList from "@/components/TeamList.astro";
const meta = {
description: "SF Civic Tech is a group of people, first and foremost. We also call ourselves technologists, planners, designers, doers, thinkers, and activists. Each week, we actively work together to improve the City and County of San Francisco, often using technology to support our efforts. By connecting people, organizations, resources, tools, and networks to build for San Francisco, we will all thrive."
};
---

<BaseLayout title="About" header="About SF Civic Tech">
<BaseLayout title="About"
header="About SF Civic Tech"
meta={meta}
>
<p>
SF Civic Tech was originally founded in 2013 as Code for San Francisco, part
of the Code for America Brigade Network. After the
Expand Down

0 comments on commit 482fc6f

Please sign in to comment.