aboutsummaryrefslogtreecommitdiff
path: root/website/src/components/Banner.astro
blob: cc6567a6468d3cc4277eb0b82badc991ee27c96d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
---
import versions from '../data/docs-versions.json';
import { docsRoute, docsTargetHref } from '../docs-path';

const { entry, locale, isFallback } = Astro.locals.starlightRoute;
const { banner } = entry.data;

const issuesUrl = 'https://github.com/herdrdev/herdr/issues/new?template=translation.yml';
const translationNotices = {
  ja: `このページの翻訳は LLM によって生成されています。誤りに気づいた場合は <a href="${issuesUrl}">GitHub で issue を開いて</a>お知らせください。`,
  'zh-cn': `本页面的翻译由 LLM 生成。如果你发现翻译有误,请<a href="${issuesUrl}">在 GitHub 上提交 issue</a> 告诉我们。`,
};
const translationNotice = locale && !isFallback ? translationNotices[locale] : undefined;
const docs = docsRoute(Astro.url.pathname);
const archivedVersion =
  docs.target !== 'stable' && docs.target !== 'preview' && docs.target !== versions.current
    ? docs.target
    : undefined;
const latestHref = docsTargetHref(docs, 'stable', versions.scopes);
const archivedNotices = {
  root: `This page documents Herdr ${archivedVersion}. <a href="${latestHref}">Switch to the latest release.</a>`,
  ja: `このページは Herdr ${archivedVersion} のドキュメントです。<a href="${latestHref}">最新版に切り替えてください。</a>`,
  'zh-cn': `本页面是 Herdr ${archivedVersion} 的文档。<a href="${latestHref}">切换到最新版本。</a>`,
};
const archivedNotice = archivedVersion ? archivedNotices[locale ?? 'root'] : undefined;
---

{banner && <div class="sl-banner" data-pagefind-ignore set:html={banner.content} />}
{archivedNotice && (
  <div class="version-notice" data-pagefind-ignore set:html={archivedNotice} />
)}
{translationNotice && (
  <div class="translation-notice" data-pagefind-ignore set:html={translationNotice} />
)}

<style>
	@layer starlight.core {
		.sl-banner {
			--__sl-banner-text: var(--sl-color-banner-text, var(--sl-color-text-invert));
			padding: var(--sl-nav-pad-y) var(--sl-nav-pad-x);
			background-color: var(--sl-color-banner-bg, var(--sl-color-bg-accent));
			color: var(--__sl-banner-text);
			line-height: var(--sl-line-height-headings);
			text-align: center;
			text-wrap: balance;
			box-shadow: var(--sl-shadow-sm);
		}
		.sl-banner :global(a) {
			color: var(--__sl-banner-text);
		}

		.translation-notice,
		.version-notice {
			padding: 0.5rem var(--sl-nav-pad-x);
			background-color: var(--sl-color-bg-nav);
			border-bottom: 1px solid var(--sl-color-hairline);
			color: var(--sl-color-gray-2);
			font-size: var(--sl-text-xs);
			line-height: var(--sl-line-height-headings);
			text-align: center;
			text-wrap: balance;
		}
		.version-notice {
			background-color: var(--sl-color-orange-low);
			border-bottom-color: var(--sl-color-orange);
			color: var(--sl-color-orange-high);
		}
		.translation-notice :global(a) {
			color: var(--sl-color-text-accent);
		}
		.version-notice :global(a) {
			color: var(--sl-color-orange-high);
		}
	}
</style>