Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions apps/website/app/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getPost, getPosts } from "@/lib/ghost";
import { SITE_URL, getPost, getPostCanonicalUrl, getPosts } from "@/lib/ghost";
import type { Metadata, ResolvingMetadata } from "next";
import Image from "next/image";
import Link from "next/link";
Expand Down Expand Up @@ -37,20 +37,23 @@ export async function generateMetadata(

const ogUrl = new URL(
"/api/og",
process.env.NODE_ENV === "production"
? "https://dokploy.com"
: "http://localhost:3001",
process.env.NODE_ENV === "production" ? SITE_URL : "http://localhost:3001",
);
ogUrl.searchParams.set("slug", slug);

const canonicalUrl = getPostCanonicalUrl(post);

return {
title: post.title,
description: post.custom_excerpt || post.excerpt,
alternates: {
canonical: canonicalUrl,
},
openGraph: {
title: post.title,
description: post.custom_excerpt || post.excerpt,
type: "article",
url: `${process.env.NEXT_PUBLIC_APP_URL}/blog/${post.slug}`,
url: canonicalUrl,
images: [
{
url: ogUrl.toString(),
Expand Down
8 changes: 7 additions & 1 deletion apps/website/app/blog/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getPosts, getTags } from "@/lib/ghost";
import { SITE_URL, getPosts, getTags } from "@/lib/ghost";
import type { Post } from "@/lib/ghost";
import { RssIcon } from "lucide-react";
import type { Metadata } from "next";
Expand All @@ -15,6 +15,12 @@ interface Tag {
export const metadata: Metadata = {
title: "Blog",
description: "Latest news, updates, and articles from Dokploy",
alternates: {
canonical: `${SITE_URL}/blog`,
},
openGraph: {
url: `${SITE_URL}/blog`,
},
};

export default async function BlogPage({
Expand Down
5 changes: 4 additions & 1 deletion apps/website/app/blog/tag/[tag]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getPostsByTag, getTags } from "@/lib/ghost";
import { SITE_URL, getPostsByTag, getTags } from "@/lib/ghost";
import type { Post } from "@/lib/ghost";
import type { Metadata } from "next";
import Image from "next/image";
Expand Down Expand Up @@ -26,6 +26,9 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
return {
title: `${tagName} Posts`,
description: `Browse all posts tagged with ${tagName}`,
alternates: {
canonical: `${SITE_URL}/blog/tag/${tag}`,
},
};
}

Expand Down
21 changes: 21 additions & 0 deletions apps/website/lib/ghost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@ export interface Post {
bio: string | null;
}>;
url: string;
canonical_url: string | null;
}

export const SITE_URL = "https://dokploy.com";

// Canonical for a post: Ghost's canonical_url if set, otherwise the post's
// own /blog/[slug] URL. Always absolute, without query string or hash.
export function getPostCanonicalUrl(
post: Pick<Post, "slug" | "canonical_url">,
) {
const fallback = `${SITE_URL}/blog/${post.slug}`;
if (!post.canonical_url) return fallback;
try {
const url = new URL(post.canonical_url, SITE_URL);
// Never canonicalize to the Ghost CMS duplicate
if (url.hostname === "cms.dokploy.com") return fallback;
if (url.hostname === "www.dokploy.com") url.hostname = "dokploy.com";
return `${url.origin}${url.pathname}`;
} catch {
return fallback;
}
}

export async function getPosts(options = {}): Promise<Post[]> {
Expand Down
Loading