@hagicode/hagilight-starlight 0.2.0 → 0.2.1-dev.13.1.46152fe

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.
@@ -0,0 +1,52 @@
1
+ ---
2
+ import { getArticlePromotionCopy } from './article-promotion.mjs';
3
+
4
+ const { lang } = Astro.props;
5
+ const copy = getArticlePromotionCopy(lang);
6
+ ---
7
+
8
+ <aside class="hagilight-article-promotion" aria-labelledby="hagilight-article-promotion-title">
9
+ <h2 id="hagilight-article-promotion-title">{copy.title}</h2>
10
+ <p>{copy.description}</p>
11
+ <a href="https://www.hagicode.com/">{copy.link}</a>
12
+ </aside>
13
+
14
+ <style>
15
+ .hagilight-article-promotion {
16
+ margin-block: 2.5rem;
17
+ padding: 1.25rem;
18
+ border: 1px solid var(--sl-color-gray-5);
19
+ border-radius: 0.75rem;
20
+ background: var(--sl-color-bg-nav);
21
+ color: var(--sl-color-text);
22
+ }
23
+
24
+ .hagilight-article-promotion h2 {
25
+ margin: 0;
26
+ font-size: var(--sl-text-h3);
27
+ }
28
+
29
+ .hagilight-article-promotion p {
30
+ margin-block: 0.75rem;
31
+ }
32
+
33
+ .hagilight-article-promotion a {
34
+ display: inline-block;
35
+ color: var(--sl-color-accent-high);
36
+ font-weight: 600;
37
+ text-decoration: underline;
38
+ text-underline-offset: 0.15em;
39
+ }
40
+
41
+ .hagilight-article-promotion a:focus-visible {
42
+ outline: 2px solid var(--sl-color-accent-high);
43
+ outline-offset: 3px;
44
+ border-radius: 2px;
45
+ }
46
+
47
+ @media (min-width: 40rem) {
48
+ .hagilight-article-promotion {
49
+ padding: 1.5rem 2rem;
50
+ }
51
+ }
52
+ </style>
@@ -1,19 +1,26 @@
1
1
  ---
2
2
  import { getCollection } from 'astro:content';
3
3
  import DefaultMarkdownContent from '@astrojs/starlight/components/MarkdownContent.astro';
4
+ import ArticlePromotion from './ArticlePromotion.astro';
4
5
  import AIDisclosureNotice from './AIDisclosureNotice.astro';
5
6
  import {
6
7
  getSourcePath,
7
8
  isTranslationLocale,
8
9
  resolveAIDisclosureFlags,
9
10
  } from './ai-disclosures.mjs';
11
+ import { resolveArticlePromotion } from './article-promotion.mjs';
10
12
 
11
- const { aiDisclosures = { isAITranslation: false, isAIAuthor: false, sourceLocale: 'root' } } = Astro.props;
13
+ const {
14
+ aiDisclosures = { isAITranslation: false, isAIAuthor: false, sourceLocale: 'root' },
15
+ hagicodePromotionEnabled = true,
16
+ } = Astro.props;
12
17
  const route = Astro.locals.starlightRoute;
13
18
  const isDocsEntry = route.entry.id !== '404' && !route.entry.id.endsWith('/404');
14
19
  const flags = isDocsEntry
15
20
  ? resolveAIDisclosureFlags(route.entry.data, aiDisclosures)
16
21
  : { isAITranslation: false, isAIAuthor: false };
22
+ const showHagicodePromotion = isDocsEntry
23
+ && resolveArticlePromotion(route.entry.data.hagicodePromotion, hagicodePromotionEnabled);
17
24
  const showTranslation = flags.isAITranslation
18
25
  && isTranslationLocale(route.entryMeta.locale, aiDisclosures.sourceLocale);
19
26
  let sourceHref;
@@ -34,3 +41,4 @@ if (showTranslation) {
34
41
  {flags.isAIAuthor && <AIDisclosureNotice kind="author" lang={route.lang} />}
35
42
  <DefaultMarkdownContent><slot /></DefaultMarkdownContent>
36
43
  {showTranslation && <AIDisclosureNotice kind="translation" lang={route.lang} sourceHref={sourceHref} />}
44
+ {showHagicodePromotion && <ArticlePromotion lang={route.lang} />}
@@ -0,0 +1,8 @@
1
+ import { z } from 'astro/zod';
2
+
3
+ const articlePromotionSchema = z.object({
4
+ hagicodePromotion: z.boolean().optional(),
5
+ });
6
+
7
+ export { articlePromotionSchema };
8
+ export default articlePromotionSchema;
@@ -0,0 +1,69 @@
1
+ const COPY = {
2
+ 'de-DE': {
3
+ title: 'Über HagiCode',
4
+ description: 'HagiCode entwickelt Werkzeuge und eine Community für Menschen, die gemeinsam Software bauen.',
5
+ link: 'HagiCode besuchen',
6
+ },
7
+ 'en-US': {
8
+ title: 'About HagiCode',
9
+ description: 'HagiCode builds tools and a community for people creating software together.',
10
+ link: 'Visit HagiCode',
11
+ },
12
+ 'es-ES': {
13
+ title: 'Acerca de HagiCode',
14
+ description: 'HagiCode crea herramientas y una comunidad para quienes desarrollan software en equipo.',
15
+ link: 'Visitar HagiCode',
16
+ },
17
+ 'fr-FR': {
18
+ title: 'À propos de HagiCode',
19
+ description: 'HagiCode crée des outils et une communauté pour les personnes qui développent des logiciels ensemble.',
20
+ link: 'Découvrir HagiCode',
21
+ },
22
+ 'ja-JP': {
23
+ title: 'HagiCodeについて',
24
+ description: 'HagiCodeは、ソフトウェアを共につくる人々のためのツールとコミュニティを提供します。',
25
+ link: 'HagiCodeを見る',
26
+ },
27
+ 'ko-KR': {
28
+ title: 'HagiCode 소개',
29
+ description: 'HagiCode는 함께 소프트웨어를 만드는 사람들을 위한 도구와 커뮤니티를 만듭니다.',
30
+ link: 'HagiCode 방문하기',
31
+ },
32
+ 'pt-BR': {
33
+ title: 'Sobre a HagiCode',
34
+ description: 'A HagiCode cria ferramentas e uma comunidade para pessoas que desenvolvem software em conjunto.',
35
+ link: 'Visite a HagiCode',
36
+ },
37
+ 'ru-RU': {
38
+ title: 'О HagiCode',
39
+ description: 'HagiCode создаёт инструменты и сообщество для тех, кто вместе разрабатывает программное обеспечение.',
40
+ link: 'Посетить HagiCode',
41
+ },
42
+ 'zh-CN': {
43
+ title: '关于 HagiCode',
44
+ description: 'HagiCode 为协作构建软件的人们提供工具与社区。',
45
+ link: '访问 HagiCode',
46
+ },
47
+ 'zh-Hant': {
48
+ title: '關於 HagiCode',
49
+ description: 'HagiCode 為協作打造軟體的人們提供工具與社群。',
50
+ link: '造訪 HagiCode',
51
+ },
52
+ };
53
+
54
+ function resolveArticlePromotion(frontmatterValue, siteDefault = true) {
55
+ if (typeof siteDefault !== 'boolean') {
56
+ throw new TypeError('Hagilight hagicodePromotion enabled default must be a boolean.');
57
+ }
58
+ if (frontmatterValue !== undefined && typeof frontmatterValue !== 'boolean') {
59
+ throw new TypeError('Hagilight frontmatter hagicodePromotion must be a boolean.');
60
+ }
61
+ return frontmatterValue ?? siteDefault;
62
+ }
63
+
64
+ function getArticlePromotionCopy(lang) {
65
+ const language = lang?.split('-')[0];
66
+ return COPY[lang] ?? COPY[language] ?? COPY['en-US'];
67
+ }
68
+
69
+ export { COPY, getArticlePromotionCopy, resolveArticlePromotion };
package/index.mjs CHANGED
@@ -63,6 +63,17 @@ function resolveAIDisclosures(config) {
63
63
  };
64
64
  }
65
65
 
66
+ function resolveHagicodePromotion(config) {
67
+ if (config === undefined) return true;
68
+ if (!config || typeof config !== 'object' || Array.isArray(config)) {
69
+ throw new TypeError('Hagilight hagicodePromotion options must be an object.');
70
+ }
71
+ if (config.enabled !== undefined && typeof config.enabled !== 'boolean') {
72
+ throw new TypeError('Hagilight hagicodePromotion enabled option must be a boolean.');
73
+ }
74
+ return config.enabled ?? true;
75
+ }
76
+
66
77
  function createConfiguredIntegration(instanceId, serializedOptions, componentIds) {
67
78
  const optionsId = `virtual:hagilight-starlight/${instanceId}/options`;
68
79
  const headerPath = componentIds.header
@@ -112,7 +123,10 @@ import MarkdownContent from ${JSON.stringify(markdownContentPath)};
112
123
  import options from '${optionsId}';
113
124
  ---
114
125
 
115
- <MarkdownContent aiDisclosures={options.aiDisclosures}><slot /></MarkdownContent>
126
+ <MarkdownContent
127
+ aiDisclosures={options.aiDisclosures}
128
+ hagicodePromotionEnabled={options.hagicodePromotionEnabled}
129
+ ><slot /></MarkdownContent>
116
130
  `;
117
131
  const headSource = `---
118
132
  import DefaultHead from '@astrojs/starlight/components/Head.astro';
@@ -180,6 +194,7 @@ export default function hagilight(options = {}) {
180
194
  }
181
195
  const analytics = options.analytics ?? {};
182
196
  const aiDisclosures = resolveAIDisclosures(options.aiDisclosures);
197
+ const hagicodePromotionEnabled = resolveHagicodePromotion(options.hagicodePromotion);
183
198
  const googleAnalyticsMeasurementId = resolveProvider(analytics.googleAnalytics, {
184
199
  name: 'Google Analytics',
185
200
  idKey: 'measurementId',
@@ -211,6 +226,7 @@ export default function hagilight(options = {}) {
211
226
  };
212
227
  const serializedOptions = {
213
228
  promotoEnabled: options.promoto?.enabled !== false,
229
+ hagicodePromotionEnabled,
214
230
  links: options.links ?? {},
215
231
  googleAnalyticsMeasurementId,
216
232
  fiftyOneLaId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hagicode/hagilight-starlight",
3
- "version": "0.2.0",
3
+ "version": "0.2.1-dev.13.1.46152fe",
4
4
  "type": "module",
5
5
  "description": "Starlight customizations for HagiCode documentation",
6
6
  "repository": {
@@ -14,11 +14,13 @@
14
14
  },
15
15
  "exports": {
16
16
  ".": "./index.mjs",
17
+ "./article-promotion-schema": "./article-promotion-schema.mjs",
17
18
  "./ai-disclosure-schema": "./ai-disclosure-schema.mjs",
18
19
  "./ContentLayoutToggle": "./ContentLayoutToggle.astro",
19
20
  "./Header": "./Header.astro",
20
21
  "./Footer": "./Footer.astro",
21
22
  "./MarkdownContent": "./MarkdownContent.astro",
23
+ "./ArticlePromotion": "./ArticlePromotion.astro",
22
24
  "./PageTitle": "./PageTitle.astro",
23
25
  "./PromotoFooter": "./PromotoFooter.astro"
24
26
  },
@@ -29,7 +31,7 @@
29
31
  "*.astro"
30
32
  ],
31
33
  "dependencies": {
32
- "@hagicode/hagilight": "0.2.0"
34
+ "@hagicode/hagilight": "0.2.1-dev.13.1.46152fe"
33
35
  },
34
36
  "peerDependencies": {
35
37
  "@astrojs/starlight": "^0.42.4",