Skip to content

Commit 8016d86

Browse files
committed
chore: Refactor base URL configuration to use site URL for absolute links in image handling
1 parent bfc18e1 commit 8016d86

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

astro.config.mjs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import mdx from '@astrojs/mdx';
44
import sitemap from '@astrojs/sitemap';
55
import { visit } from 'unist-util-visit';
66

7-
// Always deploy to https://blog.trustyai.org with root path
8-
const baseUrl = '';
7+
// Always use the full site URL for absolute links
8+
const siteUrl = 'https://blog.trustyai.org';
9+
const baseUrl = siteUrl;
910

1011
console.log('Build environment:', {
11-
site: 'https://blog.trustyai.org',
12-
baseUrl: baseUrl || '(root path)',
12+
site: siteUrl,
13+
baseUrl: baseUrl,
1314
NODE_ENV: process.env.NODE_ENV
1415
});
1516

@@ -18,9 +19,9 @@ function remarkBaseUrl() {
1819
// @ts-ignore
1920
return (tree) => {
2021
visit(tree, 'image', (node) => {
21-
if (node.url && node.url.startsWith('/') && !node.url.startsWith('/trustyai-blog/')) {
22-
console.log(`Transforming image URL: ${node.url} -> ${baseUrl}${node.url}`);
23-
node.url = `${baseUrl}${node.url}`;
22+
if (node.url && node.url.startsWith('/') && !node.url.startsWith(siteUrl)) {
23+
console.log(`Transforming image URL: ${node.url} -> ${siteUrl}${node.url}`);
24+
node.url = `${siteUrl}${node.url}`;
2425
}
2526
});
2627
// Also handle HTML img tags in MDX
@@ -29,8 +30,8 @@ function remarkBaseUrl() {
2930
node.value = node.value.replace(
3031
/src="(\/[^"]*?)"/g,
3132
(match, src) => {
32-
if (!src.startsWith('/trustyai-blog/')) {
33-
const newSrc = `${baseUrl}${src}`;
33+
if (!src.startsWith(siteUrl)) {
34+
const newSrc = `${siteUrl}${src}`;
3435
console.log(`Transforming HTML img src: ${src} -> ${newSrc}`);
3536
return `src="${newSrc}"`;
3637
}
@@ -44,7 +45,7 @@ function remarkBaseUrl() {
4445

4546
// https://astro.build/config
4647
export default defineConfig({
47-
site: 'https://blog.trustyai.org',
48+
site: siteUrl,
4849
base: baseUrl,
4950
integrations: [mdx(), sitemap()],
5051
markdown: {

0 commit comments

Comments
 (0)