Skip to content

Commit

Permalink
Make links to blog posts relative to the base
Browse files Browse the repository at this point in the history
  • Loading branch information
fwextensions committed Apr 17, 2024
1 parent ffdffe5 commit d3e459e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/components/BlogListItem.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type { CollectionEntry } from "astro:content";
import { dateFromSlug } from "@/utils/dateFromSlug";
import { getBlogImage } from "@/utils/getBlogImage";
import { base } from "@/utils/urls";
interface Props {
post: CollectionEntry<"blog">;
Expand All @@ -21,7 +22,7 @@ const {
} = Astro.props;
const imageData = await getBlogImage(image);
const backgroundImageURL = imageData?.src ?? "";
const postURL = "/blog/" + slug;
const postURL = base("/blog/" + slug);
const dateString = date?.toLocaleDateString("en-US",
{ year: "numeric", month: "short", day: "numeric" });
---
Expand Down
2 changes: 1 addition & 1 deletion src/utils/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export const githubURL = "https://github.com/sfbrigade";
export const facebookURL = "https://www.facebook.com/sfcivictech";
export const linkedinURL = "https://www.linkedin.com/company/sfbrigade/";

export const base = (url: string) => ((url.startsWith("/") ? import.meta.env.BASE_URL : "") + url).replaceAll("//", "/");
export const base = (url: string) => url.startsWith("/") ? (import.meta.env.BASE_URL + url).replace("//", "/") : url;

0 comments on commit d3e459e

Please sign in to comment.