@levino/shipyard-base 0.3.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
import { Footer as FooterComponent } from "../components";
|
|
3
|
+
import config from "virtual:shipyard/config";
|
|
3
4
|
|
|
4
|
-
const locale = Astro.currentLocale;
|
|
5
|
+
const locale = Astro.currentLocale || config.defaultLocale;
|
|
6
|
+
|
|
7
|
+
const withLocale = (path: string) =>
|
|
8
|
+
locale === config.defaultLocale ? path : `/${locale}${path}`;
|
|
5
9
|
---
|
|
6
10
|
|
|
7
11
|
<FooterComponent
|
|
8
|
-
links={[{ href:
|
|
12
|
+
links={[{ href: withLocale("/imprint"), label: "Impressum" }]}
|
|
9
13
|
copyright={{
|
|
10
14
|
href: "https://github.com/levino",
|
|
11
15
|
label: "Levin Keller",
|
package/astro/layouts/Page.astro
CHANGED
|
@@ -5,6 +5,7 @@ import config from "virtual:shipyard/config";
|
|
|
5
5
|
import { GlobalDesktopNavigation, SidebarNavigation } from "../components";
|
|
6
6
|
import type { NavigationTree, NavigationEntry } from "../../src/schemas/config";
|
|
7
7
|
import { mapObjIndexed } from "ramda";
|
|
8
|
+
import { getTitle } from "../../src/tools/title";
|
|
8
9
|
|
|
9
10
|
type Props = {
|
|
10
11
|
frontmatter?: {
|
|
@@ -18,16 +19,16 @@ type Props = {
|
|
|
18
19
|
sidebarNavigation?: NavigationTree;
|
|
19
20
|
};
|
|
20
21
|
|
|
21
|
-
const
|
|
22
|
+
const currentLocale = Astro.currentLocale || config.defaultLocale;
|
|
22
23
|
const currentPath = Astro.url.pathname;
|
|
23
24
|
const props = Astro.props.frontmatter || Astro.props;
|
|
24
25
|
|
|
25
|
-
const withLocale = (
|
|
26
|
-
|
|
26
|
+
const withLocale = (path: string) =>
|
|
27
|
+
currentLocale === config.defaultLocale ? path : `/${currentLocale}${path}`;
|
|
27
28
|
const applyLocaleAndSetActive: (navigation: NavigationTree) => NavigationTree =
|
|
28
29
|
mapObjIndexed((entry: NavigationEntry) => ({
|
|
29
30
|
...entry,
|
|
30
|
-
...(entry.href ? { href:
|
|
31
|
+
...(entry.href ? { href: withLocale(entry.href) } : {}),
|
|
31
32
|
active: entry.href === currentPath,
|
|
32
33
|
...(entry.subEntry
|
|
33
34
|
? { subEntry: applyLocaleAndSetActive(entry.subEntry) }
|
|
@@ -35,8 +36,7 @@ const applyLocaleAndSetActive: (navigation: NavigationTree) => NavigationTree =
|
|
|
35
36
|
}));
|
|
36
37
|
|
|
37
38
|
const navigation = applyLocaleAndSetActive(config.navigation);
|
|
38
|
-
const title =
|
|
39
|
-
|
|
39
|
+
const title = getTitle(config.title, props.title);
|
|
40
40
|
---
|
|
41
41
|
|
|
42
42
|
<html>
|
|
@@ -44,9 +44,7 @@ const title = `${config.title} - ${props.title}`
|
|
|
44
44
|
<meta charset="utf-8" />
|
|
45
45
|
<link rel="sitemap" href="/sitemap-index.xml" />
|
|
46
46
|
<title>
|
|
47
|
-
{
|
|
48
|
-
title
|
|
49
|
-
}
|
|
47
|
+
{title}
|
|
50
48
|
</title>
|
|
51
49
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
52
50
|
<meta name="description" content={props.description} />
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { Config } from './schemas/config'
|
|
|
3
3
|
export type { Entry } from '../astro/components/types'
|
|
4
4
|
export * from './types'
|
|
5
5
|
export type * from './schemas/config'
|
|
6
|
+
export { getTitle } from './tools/title'
|
|
6
7
|
const shipyardConfigId = 'virtual:shipyard/config'
|
|
7
8
|
|
|
8
9
|
const resolveId: Record<string, string | undefined> = {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest'
|
|
2
|
+
import { getTitle } from './title'
|
|
3
|
+
|
|
4
|
+
describe('getTitle', () => {
|
|
5
|
+
const siteTitle = 'Shipyard'
|
|
6
|
+
|
|
7
|
+
test('returns site title when page title is undefined', () => {
|
|
8
|
+
expect(getTitle(siteTitle, undefined)).toBe('Shipyard')
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
test('returns site title when page title is null', () => {
|
|
12
|
+
expect(getTitle(siteTitle, null)).toBe('Shipyard')
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
test('returns site title when page title is empty', () => {
|
|
16
|
+
expect(getTitle(siteTitle, '')).toBe('Shipyard')
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test('returns site title when page title equals site title', () => {
|
|
20
|
+
expect(getTitle(siteTitle, 'Shipyard')).toBe('Shipyard')
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test('returns combined title when page title differs', () => {
|
|
24
|
+
expect(getTitle(siteTitle, 'Blog')).toBe('Shipyard - Blog')
|
|
25
|
+
expect(getTitle(siteTitle, 'First Blog Post')).toBe(
|
|
26
|
+
'Shipyard - First Blog Post',
|
|
27
|
+
)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('handles whitespace-only page titles', () => {
|
|
31
|
+
expect(getTitle(siteTitle, ' ')).toBe('Shipyard')
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test('trims page title before comparison', () => {
|
|
35
|
+
expect(getTitle(siteTitle, ' Shipyard ')).toBe('Shipyard')
|
|
36
|
+
expect(getTitle(siteTitle, ' Blog ')).toBe('Shipyard - Blog')
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test('is case sensitive', () => {
|
|
40
|
+
expect(getTitle(siteTitle, 'shipyard')).toBe('Shipyard - shipyard')
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
test('handles special characters', () => {
|
|
44
|
+
expect(getTitle(siteTitle, 'FAQ & Help')).toBe('Shipyard - FAQ & Help')
|
|
45
|
+
})
|
|
46
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const getTitle = (
|
|
2
|
+
siteTitle: string,
|
|
3
|
+
pageTitle?: string | null,
|
|
4
|
+
): string => {
|
|
5
|
+
if (!pageTitle) return siteTitle
|
|
6
|
+
|
|
7
|
+
const trimmedPageTitle = pageTitle.trim()
|
|
8
|
+
if (!trimmedPageTitle || trimmedPageTitle === siteTitle) return siteTitle
|
|
9
|
+
|
|
10
|
+
return `${siteTitle} - ${trimmedPageTitle}`
|
|
11
|
+
}
|