Skip to content

Commit

Permalink
move pingback url to an env
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismwilliams committed Dec 6, 2024
1 parent d11d9f6 commit e95f01d
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .example.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
WEBMENTION_API_KEY=
WEBMENTION_URL=
WEBMENTION_URL=
WEBMENTION_PINGBACK=#optional
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ Replace pnpm with your choice of npm / yarn
## Configure

- Edit the config file `src/site.config.ts` for basic site meta data
- Read [this post](http://astro-cactus.chriswilliams.dev/posts/webmentions/) for adding webmentions to your site.
- Update file `astro.config.ts`
- **Important**: the site property with your own domain.
- [astro-webmanifest options](https://github.com/alextim/astro-lib/blob/main/packages/astro-webmanifest/README.md)
Expand All @@ -95,6 +94,7 @@ Replace pnpm with your choice of npm / yarn
- You can also modify the theme(s) for markdown code blocks generated by [Expressive Code](https://expressive-code.com). Astro Cactus has both a dark (dracula) and light (github-light) theme, which can be found in `src/site.config.ts`. You can find more theme(s) and options [here](https://expressive-code.com/guides/themes/#available-themes).
- Edit social links in `src/components/SocialList.astro` to add/replace your media profile. Icons can be found @ [icones.js.org](https://icones.js.org/), per [Astro Icon's instructions](https://www.astroicon.dev/guides/customization/#find-an-icon-set).
- Create/edit posts & notes for your blog within `src/content/post/` & `src/content/note/` with .md/mdx file(s). See [below](#adding-posts-and-notes) for more details.
- Read [this post](http://astro-cactus.chriswilliams.dev/posts/webmentions/) for adding webmentions to your site.
- OG Image:
- If you would like to change the style of the generated image the Satori library creates, open up `src/pages/og-image/[slug].png.ts` to the markup function where you can edit the html/tailwind-classes as necessary. You can use this [playground](https://og-playground.vercel.app/) to aid your design.
- You can also create your own og images and skip satori generating it for you by adding an ogImage property in the frontmatter with a link to the asset, an example can be found in `src/content/post/social-image.md`. More info on frontmatter can be found [here](#frontmatter)
Expand Down
5 changes: 3 additions & 2 deletions astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ export default defineConfig({
},
env: {
schema: {
WEBMENTION_API_KEY: envField.string({ context: "server", access: "secret" }),
WEBMENTION_URL: envField.string({ context: "client", access: "public", default: undefined }),
WEBMENTION_API_KEY: envField.string({ context: "server", access: "secret", optional: true }),
WEBMENTION_URL: envField.string({ context: "client", access: "public", optional: true }),
WEBMENTION_PINGBACK: envField.string({ context: "client", access: "public", optional: true }),
},
},
});
Expand Down
9 changes: 4 additions & 5 deletions src/components/BaseHead.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
import { WEBMENTION_PINGBACK, WEBMENTION_URL } from "astro:env/client";
import { siteConfig } from "@/site.config";
import type { SiteMeta } from "@/types";
import "@/styles/global.css";
Expand Down Expand Up @@ -76,12 +77,10 @@ const socialImageURL = new URL(ogImage ? ogImage : "/social-card.png", Astro.url

{/* Webmentions */}
{
siteConfig.webmentions.link && (
WEBMENTION_URL && (
<>
<link href={siteConfig.webmentions.link} rel="webmention" />
{siteConfig.webmentions.pingback && (
<link href={siteConfig.webmentions.pingback} rel="pingback" />
)}
<link href={WEBMENTION_URL} rel="webmention" />
{WEBMENTION_PINGBACK && <link href={WEBMENTION_PINGBACK} rel="pingback" />}
</>
)
}
Expand Down
8 changes: 4 additions & 4 deletions src/content/post/webmentions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ title: "Adding Webmentions to Astro Cactus"
description: "This post describes the process of adding webmentions to your own site"
publishDate: "11 Oct 2023"
tags: ["webmentions", "astro", "social"]
updatedDate: 8 April 2024
updatedDate: 6 December 2024
---

## TLDR

1. Add a link on your homepage to either your GitHub profile and/or email address as per [IndieLogin's](https://indielogin.com/setup) instructions. You _could_ do this via `src/components/SocialList.astro`, just be sure to include `isWebmention` to the relevant link if doing so.
2. Create an account @ [Webmention.io](https://webmention.io/) by entering your website's address.
3. Add the link feed and api key to and `.env` file with the key `WEBMENTION_URL` and `WEBMENTION_API_KEY` respectively. You could rename `.env.example` found in this template.
3. Add the link feed and api key to a `.env` file with the key `WEBMENTION_URL` and `WEBMENTION_API_KEY` respectively, you could rename `.env.example` found in this template. You can also add the optional `WEBMENTION_PINGBACK` link here too.
4. Go to [brid.gy](https://brid.gy/) and sign-in to each social account[s] you wish to link.
5. Publish and build your website, remember to add the api key, and it should now be ready to receive webmentions!

Expand All @@ -34,10 +34,10 @@ Firstly, you need to add a link on your site to prove ownership. If you have a l

### Sign up to Webmention.io

Next, head over to [Webmention.io](https://webmention.io/) and create an account by signing in with your domain name, e.g. `https://astro-cactus.chriswilliams.dev/`. Please note that .app TLDs don't function correctly. Once in, it will give you a couple of links for your domain to accept webmentions. Make a note of these and create a `.env` file (this template include an example `.env.example` which you could rename). Add the link feed and api key with the key/values of `WEBMENTION_URL` and `WEBMENTION_API_KEY` respectively. Please try not to publish this to a repository!
Next, head over to [Webmention.io](https://webmention.io/) and create an account by signing in with your domain name, e.g. `https://astro-cactus.chriswilliams.dev/`. Please note that .app TLDs don't function correctly. Once in, it will give you a couple of links for your domain to accept webmentions. Make a note of these and create a `.env` file (this template include an example `.env.example` which you could rename). Add the link feed and api key with the key/values of `WEBMENTION_URL` and `WEBMENTION_API_KEY` respectively, and the optional `WEBMENTION_PINGBACK` url if required. Please try not to publish this to a repository!

:::note
You don't have to include the pingback link. Maybe coincidentally, but after adding it I started to receive a higher frequency of spam in my mailbox, informing me that my website could be better. Tbh they're not wrong. I've now removed it, but it's up to you.
You don't have to include the pingback link. Maybe coincidentally, but after adding it I started to receive a higher frequency of spam in my mailbox, informing me that my website could be better. TBH they're not wrong. I've now removed it, but it's up to you.
:::

### Sign up to Brid.gy
Expand Down
5 changes: 0 additions & 5 deletions src/site.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ export const siteConfig: SiteConfig = {
ogLocale: "en_GB",
// Used to construct the meta title property found in src/components/BaseHead.astro L:11, and webmanifest name found in astro.config.ts L:42
title: "Astro Theme Cactus",
webmentions: {
// Webmention.io API endpoint. Get your own here: https://webmention.io/, and follow this blog post: https://astro-cactus.chriswilliams.dev/posts/webmentions/
link: process.env.WEBMENTIONS_URL,
pingback: undefined,
},
};

// Used to generate links in both the Header & Footer.
Expand Down
4 changes: 0 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ export interface SiteConfig {
lang: string;
ogLocale: string;
title: string;
webmentions: {
link?: string | undefined;
pingback?: string | undefined;
};
}

export interface PaginationLink {
Expand Down

0 comments on commit e95f01d

Please sign in to comment.