Skip to content

Commit 8c972c0

Browse files
committed
use Astro.site
1 parent f037f8c commit 8c972c0

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

docs/tutorialkit.dev/src/content/docs/guides/deployment.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ You can learn more about the build process in the [Astro documentation](https://
3636

3737
## Environment variables
3838

39-
The [`BASE_URL`](https://docs.astro.build/en/guides/environment-variables/#default-environment-variables) environment variable should point to your website's absolute URL.
39+
The [`site`](https://docs.astro.build/fr/reference/configuration-reference/#site) configuration should point to your website's absolute URL.
4040
This will allow to compute absolute URLs for SEO metadata.
4141

4242
Example:
43-
```
44-
BASE_URL="https://tutorialkit.dev"
43+
```json
44+
// astro.config.mjs
45+
site:"https://tutorialkit.dev"
4546
```
4647

4748
## Headers configuration

packages/astro/src/default/components/MetaTags.astro

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ interface Props {
88
meta?: MetaTagsConfig;
99
}
1010
const { meta = {} } = Astro.props;
11+
const site = Astro.site?.toString();
1112
let imageUrl;
1213
if (meta.image) {
13-
imageUrl = readPublicImage(meta.image);
14+
imageUrl = readPublicImage(meta.image, site);
1415
if (!imageUrl) {
1516
console.warn(`Image ${meta.image} not found in "/public" folder`);
1617
}
1718
}
18-
imageUrl ??= readLogoFile();
19-
const faviconUrl = readFaviconFile();
19+
imageUrl ??= readLogoFile('logo', site);
20+
const faviconUrl = readFaviconFile('favicon', site);
2021
---
2122

2223
<meta charset="UTF-8" />
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { readPublicImage } from './publicImage';
22

3-
export function readFaviconFile(faviconPrefix: string = 'favicon') {
3+
export function readFaviconFile(faviconPrefix: string = 'favicon', site?: string) {
44
const faviconFilename = `${faviconPrefix}.svg`;
5-
return readPublicImage(faviconFilename);
5+
return readPublicImage(faviconFilename, site);
66
}

packages/astro/src/default/utils/logo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { LOGO_EXTENSIONS } from './constants';
22
import { readPublicImage } from './publicImage';
33

4-
export function readLogoFile(logoPrefix: string = 'logo') {
4+
export function readLogoFile(logoPrefix: string = 'logo', site?: string) {
55
let logo;
66

77
for (const logoExt of LOGO_EXTENSIONS) {
88
const logoFilename = `${logoPrefix}.${logoExt}`;
9-
logo = readPublicImage(logoFilename);
9+
logo = readPublicImage(logoFilename, site);
1010

1111
if (logo) {
1212
break;

packages/astro/src/default/utils/publicImage.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@ import fs from 'node:fs';
22
import path from 'node:path';
33
import { joinPaths } from './url';
44

5-
export function readPublicImage(filename: string) {
5+
export function readPublicImage(filename: string, site?: string) {
66
let image;
77
const exists = fs.existsSync(path.join('public', filename));
88

9-
if (exists) {
10-
image = joinPaths(import.meta.env.BASE_URL, filename);
9+
if (!exists) {
10+
return;
11+
}
12+
13+
image = joinPaths(import.meta.env.BASE_URL, filename);
14+
15+
if (site) {
16+
image = joinPaths(site, image);
1117
}
1218

1319
return image;

0 commit comments

Comments
 (0)