Skip to content

Commit b70c2ce

Browse files
fix: load favicon defined in afterpython.toml correctly in website
1 parent d235f57 commit b70c2ce

6 files changed

Lines changed: 14 additions & 5 deletions

File tree

afterpython/_website/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@afterpython/project-website-template",
3-
"version": "0.3.5",
3+
"version": "0.3.8",
44
"license": "Apache-2.0",
55
"type": "module",
66
"packageManager": "pnpm@11.1.1",

afterpython/_website/src/app.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
5-
<link rel="icon" type="image/svg+xml" href="%sveltekit.assets%/favicon.svg" />
6-
<link rel="icon" type="image/x-icon" href="%sveltekit.assets%/favicon.ico" />
75
<meta name="viewport" content="width=device-width, initial-scale=1" />
86
<script>
97
// Prevent theme flash by applying theme before page renders

afterpython/_website/src/routes/+layout.server.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { CONTENT_TYPES } from '$lib/utils/content';
33
import { existsSync } from 'fs';
44
import { resolve } from 'path';
55

6+
const DEFAULT_FAVICON = 'favicon.ico';
7+
68
export const prerender = true;
79

810
async function checkContentType(type: string): Promise<boolean> {
@@ -29,6 +31,7 @@ function checkApiReferenceExists(): boolean {
2931
type LogoMetadata = {
3032
logo?: string;
3133
logo_dark?: string;
34+
favicon?: string;
3235
};
3336

3437
export const load: LayoutServerLoad = async () => {
@@ -52,6 +55,7 @@ export const load: LayoutServerLoad = async () => {
5255

5356
return {
5457
...metadataData,
58+
favicon: metadataData.favicon ?? DEFAULT_FAVICON,
5559
metadataError: null,
5660
contentTypes
5761
};
@@ -68,7 +72,8 @@ export const load: LayoutServerLoad = async () => {
6872
project_url: [],
6973
metadataError:
7074
'Project metadata not found. Please ensure metadata.json exists in the static folder. Did you forget to run `ap build`?',
71-
contentTypes: emptyContentTypes
75+
contentTypes: emptyContentTypes,
76+
favicon: DEFAULT_FAVICON
7277
};
7378
}
7479
};

afterpython/_website/src/routes/+layout.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
1313
let { data, children }: LayoutProps = $props();
1414
15+
const faviconType = $derived(
16+
data.favicon?.endsWith('.svg') ? 'image/svg+xml' : 'image/x-icon'
17+
);
18+
1519
// Extract repository URL safely
1620
const repositoryUrl = $derived(
1721
data.project_url?.find((url: string) => url.startsWith('repository,'))?.split(', ')[1]
@@ -23,6 +27,7 @@
2327

2428
<svelte:head>
2529
<title>{siteTitle}</title>
30+
<link rel="icon" type={faviconType} href={resolve(`/${data.favicon}`)} />
2631
</svelte:head>
2732

2833
<div class="flex min-h-screen flex-col bg-bg50">

afterpython/afterpython.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ url = "https://afterpython.org" # used in myst.yml's venue.url
55

66
[website]
77
url = "https://afterpython.afterpython.org"
8-
favicon = "favicon.ico"
8+
favicon = "favicon.svg"
99
logo = "logo.svg"
1010
logo_dark = "logo.svg"
1111
thumbnail = "thumbnail.png" # thumbnail for the website, also used as default thumbnail for all content types, e.g. blog posts, tutorials, examples, and guides

src/afterpython/builders/metadata.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def build_metadata():
6262
# slash form that the Svelte side can hand straight to `asset()`.
6363
metadata_json["logo"] = _resolve_logo_path(website.get("logo", ""))
6464
metadata_json["logo_dark"] = _resolve_logo_path(website.get("logo_dark", ""))
65+
metadata_json["favicon"] = _resolve_logo_path(website.get("favicon", ""))
6566

6667
with open(build_path / "metadata.json", "w") as f:
6768
json.dump(metadata_json, f, indent=2)

0 commit comments

Comments
 (0)