@ninjainfosys/site-kit 0.1.0 → 0.2.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ninjainfosys/site-kit",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Shared blog, glossary, SEO, layout and build tooling for the Ninja Infosys Astro marketing sites.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,5 +1,5 @@
1
1
  ---
2
- import { CONTACT_EMAIL, CONTACT_PHONE_DISPLAY, CONTACT_PHONE_TEL, OFFICE_LINE, LEGAL_ADDRESS_LINE, SOCIAL_PROFILES, PARENT_COMPANY_NAME, PARENT_COMPANY_URL, SITE_NAME, kit } from '../../config';
2
+ import { COMPANY, CONTACT_EMAIL, CONTACT_PHONE_DISPLAY, CONTACT_PHONE_TEL, OFFICE_LINE, LEGAL_ADDRESS_LINE, SOCIAL_PROFILES, PARENT_COMPANY_NAME, PARENT_COMPANY_URL, SITE_NAME, kit } from '../../config';
3
3
  import { siFacebook, siInstagram, siTiktok } from 'simple-icons';
4
4
 
5
5
  // LinkedIn is not in simple-icons; this is its standard "in" mark.
@@ -10,13 +10,15 @@ const icon: Record<string, { name: string; path: string }> = {
10
10
  tiktok: { name: 'TikTok', path: siTiktok.path },
11
11
  linkedin: { name: 'LinkedIn', path: linkedin },
12
12
  };
13
- const social = SOCIAL_PROFILES.map((href) => ({ href, ...icon[Object.keys(icon).find((k) => href.includes(k))!] }));
13
+ const social = (SOCIAL_PROFILES ?? []).map((href) => ({ href, ...icon[Object.keys(icon).find((k) => href.includes(k))!] }));
14
14
  ---
15
15
  <footer class="site-footer">
16
16
  <div class="wrap">
17
17
  <div class="top">
18
18
  <div class="brand">
19
- <img src={kit.footer.mark.src} alt="" width={kit.footer.mark.width} height={kit.footer.mark.height} class="cloud" aria-hidden="true" />
19
+ {kit.footer.mark.text
20
+ ? <p class="mark"><img src={kit.footer.mark.src} alt="" width={kit.footer.mark.width} height={kit.footer.mark.height} class="cloud" aria-hidden="true" /><span class="mark-text">{kit.footer.mark.text}</span></p>
21
+ : <img src={kit.footer.mark.src} alt="" width={kit.footer.mark.width} height={kit.footer.mark.height} class="cloud" aria-hidden="true" />}
20
22
  <p class="contact">
21
23
  <a href={CONTACT_PHONE_TEL}>{CONTACT_PHONE_DISPLAY}</a><br />
22
24
  <a href={`mailto:${CONTACT_EMAIL}`}>{CONTACT_EMAIL}</a><br />
@@ -35,7 +37,9 @@ const social = SOCIAL_PROFILES.map((href) => ({ href, ...icon[Object.keys(icon).
35
37
  </nav>
36
38
  ))}
37
39
  </div>
38
- <p class="legal muted">© {new Date().getFullYear()} <a href={PARENT_COMPANY_URL} rel="noopener">{PARENT_COMPANY_NAME}</a>, {LEGAL_ADDRESS_LINE}</p>
40
+ {kit.footer.legal === 'company'
41
+ ? <p class="legal muted">© {new Date().getFullYear()} {COMPANY}, {LEGAL_ADDRESS_LINE} Part of <a href={PARENT_COMPANY_URL} rel="noopener">{PARENT_COMPANY_NAME}</a>.</p>
42
+ : <p class="legal muted">© {new Date().getFullYear()} <a href={PARENT_COMPANY_URL} rel="noopener">{PARENT_COMPANY_NAME}</a>, {LEGAL_ADDRESS_LINE}</p>}
39
43
  </div>
40
44
  </footer>
41
45
 
@@ -23,8 +23,10 @@ const current = (href: string) => (path === href || path.startsWith(`${href}/`)
23
23
  <header class="site-header">
24
24
  <div class="wrap bar">
25
25
  <a class="logo" href="/" aria-label={homeLabel}>
26
- <img src={logo.light} alt={logo.alt} width={logo.width} height={logo.height} class="logo-light" />
27
- <img src={logo.dark} alt="" width={logo.width} height={logo.height} class="logo-dark" aria-hidden="true" />
26
+ {logo.alt
27
+ ? <img src={logo.light} alt={logo.alt} width={logo.width} height={logo.height} class="logo-light" />
28
+ : <img src={logo.light} alt="" width={logo.width} height={logo.height} class="logo-light" />}
29
+ <img src={logo.dark} alt="" width={logo.width} height={logo.height} class="logo-dark" aria-hidden="true" />{logo.text && <>{' '}<span class="logo-text">{logo.text}</span></>}
28
30
  </a>
29
31
 
30
32
  <nav class="nav-wide" aria-label="Main">
package/src/config.ts CHANGED
@@ -18,7 +18,8 @@ export const CONTACT_PHONE_JSONLD = get('CONTACT_PHONE_JSONLD');
18
18
  export const OFFICE_LINE = get('OFFICE_LINE');
19
19
  export const LEGAL_ADDRESS = get('LEGAL_ADDRESS');
20
20
  export const LEGAL_ADDRESS_LINE = get('LEGAL_ADDRESS_LINE');
21
- export const SOCIAL_PROFILES = get('SOCIAL_PROFILES') ?? [];
21
+ /** Undefined when the site has none to declare; an empty list is still sent as `sameAs: []`. */
22
+ export const SOCIAL_PROFILES = get('SOCIAL_PROFILES');
22
23
  export const PARENT_COMPANY_NAME = get('PARENT_COMPANY_NAME');
23
24
  export const PARENT_COMPANY_URL = get('PARENT_COMPANY_URL');
24
25
  export const PARENT_COMPANY_ID = get('PARENT_COMPANY_ID');
package/src/contract.ts CHANGED
@@ -70,7 +70,8 @@ export interface HeaderGroup {
70
70
 
71
71
  export interface HeaderConfig {
72
72
  homeLabel: string;
73
- logo: { light: string; dark: string; alt: string; width: number; height: number };
73
+ /** `text` sets a wordmark beside the logo images. */
74
+ logo: { light: string; dark: string; alt: string; width: number; height: number; text?: string };
74
75
  /** The thin strip above the bar. `text` is plain, `mono` is set in the mono face. */
75
76
  utility: { lead: { href: string; text: string; mono?: string }; links: HeaderLink[] };
76
77
  groups: HeaderGroup[];
@@ -85,7 +86,10 @@ export interface HeaderConfig {
85
86
 
86
87
  export interface FooterConfig {
87
88
  /** The mark above the contact lines. */
88
- mark: { src: string; width: number; height: number };
89
+ /** `text` sets a wordmark beside the mark. */
90
+ mark: { src: string; width: number; height: number; text?: string };
91
+ /** 'parent' links the parent company; 'company' names the company, then "Part of <parent>". */
92
+ legal?: 'parent' | 'company';
89
93
  columns: { title: string; links: HeaderLink[] }[];
90
94
  }
91
95
 
@@ -93,8 +97,12 @@ export interface OgConfig {
93
97
  background: string;
94
98
  ink: string;
95
99
  muted: string;
96
- /** SVG in public/ drawn beside the site name; `from` is the fill replaced by `fill`. */
97
- mark: { file: string; from: string; fill: string; width: number; height: number };
100
+ /** Font from @fontsource/<package>, loaded at 400 and 600; default Poppins. */
101
+ font?: { family: string; package: string };
102
+ /** Name beside the mark; default is SITE_NAME at 40px, weight 600. */
103
+ name?: { text: string; size: number; weight: number };
104
+ /** SVG in public/ drawn beside the site name; `from` is the fill replaced by `fill` (leave both out to use it as is). */
105
+ mark: { file: string; from?: string; fill?: string; width: number; height: number };
98
106
  /** Pages the site owns: static pages, products, solutions. The kit adds blog, tag and glossary cards. */
99
107
  pages: () => { slug: string; title: string }[];
100
108
  }
@@ -1,10 +1,37 @@
1
1
  // The Astro integration every site adds: `integrations: [siteKit()]`. Plain
2
2
  // JavaScript so Node can load it from node_modules when astro.config runs.
3
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
3
4
  import { fileURLToPath } from 'node:url';
4
5
  import { join } from 'node:path';
5
6
  import { rehypeFigures } from './lib/rehype-figures.mjs';
6
7
 
7
8
  const PACKAGE = '@ninjainfosys/site-kit';
9
+ const BLOG_IMAGES = 'virtual:site-kit/blog-images';
10
+ const IMAGE = /\.(jpe?g|png|webp|avif)$/i;
11
+
12
+ /**
13
+ * The images of the posts that will be published, as one module. A glob over
14
+ * src/assets/blog would also emit the images of draft posts (and of folders
15
+ * with no post yet) into dist; this lists only posts that ship. The dev server
16
+ * lists every post so drafts can be reviewed.
17
+ */
18
+ function blogImages(root, dev) {
19
+ const posts = join(root, 'src/content/blog');
20
+ const assets = join(root, 'src/assets/blog');
21
+ const ids = [];
22
+ if (existsSync(posts) && existsSync(assets)) {
23
+ for (const f of readdirSync(posts).filter((x) => x.endsWith('.md'))) {
24
+ const fm = readFileSync(join(posts, f), 'utf8').match(/^---\r?\n([\s\S]*?)\r?\n---/)?.[1] ?? '';
25
+ if (!dev && /^draft:\s*true\s*$/m.test(fm)) continue;
26
+ const slug = f.replace(/\.md$/, '');
27
+ const dir = join(assets, slug);
28
+ if (existsSync(dir)) for (const img of readdirSync(dir).filter((x) => IMAGE.test(x)).sort()) ids.push(`/src/assets/blog/${slug}/${img}`);
29
+ }
30
+ }
31
+ const imports = ids.map((id, i) => `import m${i} from ${JSON.stringify(id)};`).join('\n');
32
+ const entries = ids.map((id, i) => `${JSON.stringify(id)}: { default: m${i} }`).join(', ');
33
+ return `${imports}\nexport default { ${entries} };\n`;
34
+ }
8
35
 
9
36
  // Pages that are the same on every site. The site turns one off with
10
37
  // `siteKit({ pages: { glossary: false } })` and supplies its own.
@@ -33,13 +60,21 @@ export default function siteKit(options = {}) {
33
60
  return {
34
61
  name: PACKAGE,
35
62
  hooks: {
36
- 'astro:config:setup': ({ config, updateConfig, injectRoute }) => {
63
+ 'astro:config:setup': ({ config, command, updateConfig, injectRoute }) => {
64
+ const root = fileURLToPath(config.root);
37
65
  updateConfig({
38
66
  markdown: { rehypePlugins: [rehypeFigures] },
39
67
  vite: {
68
+ plugins: [
69
+ {
70
+ name: 'site-kit-blog-images',
71
+ resolveId: (id) => (id === BLOG_IMAGES ? `\0${BLOG_IMAGES}` : null),
72
+ load: (id) => (id === `\0${BLOG_IMAGES}` ? blogImages(root, command === 'dev') : null),
73
+ },
74
+ ],
40
75
  resolve: {
41
76
  // Kit code imports the site's own modules as '@site/...'.
42
- alias: { '@site': join(fileURLToPath(config.root), 'src') },
77
+ alias: { '@site': join(root, 'src') },
43
78
  // One copy of Astro and its runtime, whichever package a file lives in.
44
79
  dedupe: ['astro'],
45
80
  },
package/src/lib/seo.ts CHANGED
@@ -27,7 +27,7 @@ export function orgJsonLd() {
27
27
  ...(COMPANY ? { legalName: COMPANY } : {}),
28
28
  url: `${SITE_URL}/`,
29
29
  logo: abs(kit.seo.logo),
30
- ...(SOCIAL_PROFILES.length ? { sameAs: [...SOCIAL_PROFILES] } : {}),
30
+ ...(SOCIAL_PROFILES ? { sameAs: [...SOCIAL_PROFILES] } : {}),
31
31
  ...(PARENT_COMPANY_ID ? { parentOrganization: { '@type': 'Organization', '@id': PARENT_COMPANY_ID, name: PARENT_COMPANY_NAME, url: PARENT_COMPANY_URL } } : {}),
32
32
  ...(CONTACT_EMAIL ? { email: CONTACT_EMAIL } : {}),
33
33
  ...(CONTACT_PHONE_JSONLD ? { telephone: CONTACT_PHONE_JSONLD } : {}),
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  import ChevronDown from '@lucide/astro/icons/chevron-down';
3
3
  import { render } from 'astro:content';
4
+ import blogImages from 'virtual:site-kit/blog-images';
4
5
  import { Image, getImage } from 'astro:assets';
5
6
  import { LICENCES } from '../../lib/blog-schema';
6
7
  import Base from '@site/layouts/Base.astro';
@@ -31,7 +32,7 @@ const image = d.cover ? (await getImage({ src: d.cover, width: 1200, height: 630
31
32
  const credits = d.credits.filter((c) => !('own' in c));
32
33
  // Every credited image as an ImageObject with its licence, so search engines
33
34
  // show the right credit (and the Licensable badge) in image results.
34
- const files = import.meta.glob<{ default: ImageMetadata }>('/src/assets/blog/**/*.{jpg,jpeg,png,webp,avif}', { eager: true });
35
+ const files = blogImages as Record<string, { default: ImageMetadata }>;
35
36
  const imageObjects = await Promise.all(
36
37
  d.credits.map(async (c) => {
37
38
  const mod = files[`/src/assets/blog/${post.id}/${c.file}`];
@@ -12,9 +12,10 @@ const { Resvg } = createRequire(import.meta.url)('@resvg/resvg-js') as typeof im
12
12
  import { glossary } from '../../lib/glossary';
13
13
  import { SITE_NAME, SITE_URL, kit } from '../../config';
14
14
 
15
- const font = (w: number) => readFileSync(`node_modules/@fontsource/poppins/files/poppins-latin-${w}-normal.woff`);
16
15
  const { og } = kit;
17
- const mark = `data:image/svg+xml;base64,${Buffer.from(readFileSync(`public/${og.mark.file}`, 'utf8').replace(og.mark.from, og.mark.fill)).toString('base64')}`;
16
+ const face = og.font ?? { family: 'Poppins', package: 'poppins' };
17
+ const font = (w: number) => readFileSync(`node_modules/@fontsource/${face.package}/files/${face.package}-latin-${w}-normal.woff`);
18
+ const mark = `data:image/svg+xml;base64,${Buffer.from(readFileSync(`public/${og.mark.file}`, 'utf8').replace(og.mark.from ?? '', og.mark.fill ?? '')).toString('base64')}`;
18
19
 
19
20
  export async function getStaticPaths() {
20
21
  const posts = await getCollection('blog');
@@ -36,7 +37,7 @@ export async function GET({ props }: APIContext) {
36
37
  {
37
38
  type: 'div',
38
39
  props: {
39
- style: { width: 1200, height: 630, display: 'flex', flexDirection: 'column', justifyContent: 'space-between', padding: 72, background: og.background, color: og.ink, fontFamily: 'Poppins' },
40
+ style: { width: 1200, height: 630, display: 'flex', flexDirection: 'column', justifyContent: 'space-between', padding: 72, background: og.background, color: og.ink, fontFamily: face.family },
40
41
  children: [
41
42
  {
42
43
  type: 'div',
@@ -44,7 +45,7 @@ export async function GET({ props }: APIContext) {
44
45
  style: { display: 'flex', alignItems: 'center', gap: 20 },
45
46
  children: [
46
47
  { type: 'img', props: { src: mark, width: og.mark.width, height: og.mark.height } },
47
- { type: 'div', props: { style: { fontSize: 40, fontWeight: 600 }, children: SITE_NAME } },
48
+ { type: 'div', props: { style: { fontSize: og.name?.size ?? 40, fontWeight: og.name?.weight ?? 600 }, children: og.name?.text ?? SITE_NAME } },
48
49
  ],
49
50
  },
50
51
  },
@@ -53,7 +54,7 @@ export async function GET({ props }: APIContext) {
53
54
  ],
54
55
  },
55
56
  },
56
- { width: 1200, height: 630, fonts: [{ name: 'Poppins', data: font(400), weight: 400 }, { name: 'Poppins', data: font(600), weight: 600 }] },
57
+ { width: 1200, height: 630, fonts: [{ name: face.family, data: font(400), weight: 400 }, { name: face.family, data: font(600), weight: 600 }] },
57
58
  );
58
59
  const png = new Resvg(svg).render().asPng();
59
60
  return new Response(png, { headers: { 'content-type': 'image/png' } });
@@ -162,6 +162,3 @@ button, input, select, textarea { font: inherit; color: inherit; }
162
162
  body { background: #FFFFFF; color: #000000; font-size: 12pt; }
163
163
  a { color: inherit; }
164
164
  }
165
-
166
- /* Blog: headings and post titles in the reading serif. */
167
- .blog-serif h1, .blog-serif h2, .blog-serif h3 { font-family: 'Source Serif 4 Variable', 'Serif Fallback', Georgia, serif; font-weight: 600; }
@@ -0,0 +1,2 @@
1
+ /* Blog: headings and post titles in the reading serif. */
2
+ .blog-serif h1, .blog-serif h2, .blog-serif h3 { font-family: 'Source Serif 4 Variable', 'Serif Fallback', Georgia, serif; font-weight: 600; }
@@ -0,0 +1,4 @@
1
+ declare module 'virtual:site-kit/blog-images' {
2
+ const images: Record<string, { default: unknown }>;
3
+ export default images;
4
+ }