Skip to content

Commit e88471c

Browse files
committed
refactor: Head are not single components
1 parent 2aff756 commit e88471c

14 files changed

Lines changed: 183 additions & 74 deletions
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {getInteractConfig} from "@combostrap/interact/config";
2+
import type {LayoutProps} from "@combostrap/interact/types";
3+
4+
/**
5+
* Head base meta
6+
* Relative path and anchor links in the page are
7+
* calculated by the browser relative to the path name of this URL
8+
*
9+
* In the root, we need to add a slash otherwise the relative path is calculated
10+
* against the parent path (if there is a base, there is another parent)
11+
*
12+
* ie <base href="/reference/component/">
13+
* works across domains because it's domain-agnostic — it always resolves relative to wherever the site is hosted.
14+
*/
15+
// noinspection JSUnusedLocalSymbols
16+
export default function HeadBase({context}: LayoutProps) {
17+
const interactConfig = getInteractConfig();
18+
let baseHeadURL = (interactConfig.site.base != "/" ? interactConfig.site.base : "") + context.url.pathname;
19+
return (
20+
<base href={baseHeadURL}/>
21+
)
22+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type {LayoutProps} from "@combostrap/interact/types";
2+
3+
// noinspection JSUnusedLocalSymbols
4+
export default function HeadPageElements({page}: LayoutProps) {
5+
return page.headElements;
6+
}

src/resources/components/heads/HeadTitle.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type {HeadProps} from "@/components/partials/Head";
21
import {getInteractConfig} from "../../../interact/config/interactConfig";
2+
import type {LayoutProps} from "@combostrap/interact/types";
33

44
// noinspection JSUnusedLocalSymbols,JSUnusedGlobalSymbols
5-
export default function HeadTitle({page, context}: HeadProps) {
5+
export default function HeadTitle({page, context}: LayoutProps) {
66

77
const interactConfig = getInteractConfig();
88
let frontmatter = page?.frontmatter;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type {LayoutProps} from "@combostrap/interact/types";
2+
3+
/**
4+
* The markdown alternate version
5+
* (URL Path name should have already the base)
6+
*/
7+
// noinspection JSUnusedLocalSymbols
8+
export default function LinkAlternateMarkdown({context}: LayoutProps) {
9+
let markdownAlternateHref = context.url.pathname.endsWith("/") ? context.url.pathname + "index.md" : context.url.pathname + ".md"
10+
return (
11+
<link rel="alternate" type="text/markdown" href={markdownAlternateHref}/>
12+
)
13+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {getInteractConfig} from "@combostrap/interact/config";
2+
3+
// noinspection JSUnusedLocalSymbols
4+
export default function LinkFavicons() {
5+
const interactConfig = getInteractConfig();
6+
if (!interactConfig.site.favicons) {
7+
return;
8+
}
9+
return (
10+
<>
11+
{Object.entries(interactConfig.site.favicons).map(([faviconPath, faviconProperties], index) => {
12+
if (!faviconProperties) {
13+
return;
14+
}
15+
return (
16+
<link key={index}
17+
rel={faviconProperties.rel}
18+
href={faviconProperties.image?.href ? faviconProperties.image.href : `/${faviconPath}`}
19+
type={faviconProperties.image?.type}
20+
sizes={faviconProperties.image?.width && faviconProperties.image?.height ? `${faviconProperties.image.width}x${faviconProperties.image.height}` : ''}
21+
/>
22+
)
23+
})}
24+
</>
25+
)
26+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {getInteractConfig} from "@combostrap/interact/config";
2+
3+
// noinspection JSUnusedLocalSymbols
4+
export default function LinkManifest() {
5+
const interactConfig = getInteractConfig();
6+
if (!interactConfig.site.manifest) {
7+
return;
8+
}
9+
return (
10+
<link rel="manifest" href={interactConfig.site.manifest}/>
11+
)
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type {LayoutProps} from "@combostrap/interact/types";
2+
3+
// noinspection JSUnusedLocalSymbols
4+
export default function MetaDescription({page}: LayoutProps) {
5+
let description = page?.frontmatter?.description;
6+
if (!description) {
7+
return;
8+
}
9+
return (
10+
<meta name="description" content={description}/>
11+
)
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
// noinspection JSUnusedLocalSymbols
3+
export default function MetaGenerator() {
4+
return (
5+
<meta name="generator" content="Interact"/>
6+
)
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type {LayoutProps} from "@combostrap/interact/types";
2+
3+
// noinspection JSUnusedLocalSymbols
4+
export default function MetaKeywords({page}: LayoutProps) {
5+
let keyWords = page?.frontmatter?.keyWords;
6+
if (!keyWords) {
7+
return;
8+
}
9+
return (
10+
<meta name="keywords" content={keyWords}/>
11+
)
12+
}

src/resources/components/heads/MetaLastModified.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import type {HeadProps} from "@/components/partials/Head";
1+
import type {LayoutProps} from "@combostrap/interact/types";
22

33
/**
44
* Last modified
55
*/
66
// noinspection JSUnusedLocalSymbols,JSUnusedGlobalSymbols
7-
export default function MetaLastModified({context}: HeadProps) {
7+
export default function MetaLastModified({context}: LayoutProps) {
88
if (context.meta.lastModifiedPage == null) {
99
return;
1010
}

0 commit comments

Comments
 (0)