@hkdigital/lib-core 0.5.93 → 0.5.95
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/dist/config/generators/imagetools.d.ts +14 -0
- package/dist/config/generators/imagetools.js +55 -0
- package/dist/config/imagetools.d.ts +12 -0
- package/dist/meta/README.md +92 -0
- package/dist/meta/components/Favicons.svelte +30 -0
- package/dist/meta/components/Favicons.svelte.d.ts +103 -0
- package/dist/meta/components/PWA.svelte +51 -0
- package/dist/meta/components/PWA.svelte.d.ts +103 -0
- package/dist/meta/components/SEO.svelte +146 -0
- package/dist/meta/components/SEO.svelte.d.ts +108 -0
- package/dist/meta/components.d.ts +3 -0
- package/dist/meta/components.js +3 -0
- package/dist/meta/config.typedef.d.ts +98 -0
- package/dist/meta/config.typedef.js +44 -0
- package/dist/meta/templates/README.md +150 -0
- package/dist/meta/templates/lib/assets/meta/favicon.png +0 -0
- package/dist/meta/templates/lib/assets/meta/preview-landscape.png +0 -0
- package/dist/meta/templates/lib/assets/meta/preview-square.png +0 -0
- package/dist/meta/templates/lib/config/meta.d.ts +63 -0
- package/dist/meta/templates/lib/config/meta.js +112 -0
- package/dist/meta/templates/lib/meta.d.ts +7 -0
- package/dist/meta/templates/lib/meta.js +23 -0
- package/dist/meta/templates/routes/(meta)/manifest.json/+server.d.ts +2 -0
- package/dist/meta/templates/routes/(meta)/manifest.json/+server.js +42 -0
- package/dist/meta/templates/routes/(meta)/robots.txt/+server.d.ts +2 -0
- package/dist/meta/templates/routes/(meta)/robots.txt/+server.js +9 -0
- package/dist/meta/templates/routes/(meta)/sitemap.xml/+server.d.ts +2 -0
- package/dist/meta/templates/routes/(meta)/sitemap.xml/+server.js +14 -0
- package/dist/meta/typedef.d.ts +3 -0
- package/dist/meta/typedef.js +14 -0
- package/dist/meta/utils/lang.d.ts +29 -0
- package/dist/meta/utils/lang.js +84 -0
- package/dist/meta/utils/robots.d.ts +1 -0
- package/dist/meta/utils/robots.js +1 -0
- package/dist/meta/utils/sitemap.d.ts +1 -0
- package/dist/meta/utils/sitemap.js +1 -0
- package/dist/meta/utils.d.ts +3 -0
- package/dist/meta/utils.js +11 -0
- package/package.json +3 -3
- package/scripts/validate-imports.mjs +51 -0
- package/dist/meta/robots.d.ts +0 -1
- package/dist/meta/robots.js +0 -5
- package/dist/meta/sitemap.d.ts +0 -1
- package/dist/meta/sitemap.js +0 -5
- /package/dist/meta/{robots/index.d.ts → utils/robots/robots.d.ts} +0 -0
- /package/dist/meta/{robots/index.js → utils/robots/robots.js} +0 -0
- /package/dist/meta/{robots → utils/robots}/typedef.d.ts +0 -0
- /package/dist/meta/{robots → utils/robots}/typedef.js +0 -0
- /package/dist/meta/{sitemap/index.d.ts → utils/sitemap/sitemap.d.ts} +0 -0
- /package/dist/meta/{sitemap/index.js → utils/sitemap/sitemap.js} +0 -0
- /package/dist/meta/{sitemap → utils/sitemap}/typedef.d.ts +0 -0
- /package/dist/meta/{sitemap → utils/sitemap}/typedef.js +0 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { generateSitemap } from '../../../../utils.js';
|
|
2
|
+
import { siteRoutes } from '../../../../../config/meta.js';
|
|
3
|
+
|
|
4
|
+
/** @type {import('@sveltejs/kit').RequestHandler} */
|
|
5
|
+
export const GET = async ({ url }) => {
|
|
6
|
+
const sitemap = generateSitemap(url.origin, siteRoutes);
|
|
7
|
+
|
|
8
|
+
return new Response(sitemap, {
|
|
9
|
+
headers: {
|
|
10
|
+
'Content-Type': 'application/xml',
|
|
11
|
+
'Cache-Control': 'max-age=0, s-maxage=3600'
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for meta utilities
|
|
3
|
+
*
|
|
4
|
+
* Re-exports all typedefs from utils subfolder for convenient importing
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Re-export config typedefs
|
|
8
|
+
export * from './config.typedef.js';
|
|
9
|
+
|
|
10
|
+
// Re-export robots typedefs
|
|
11
|
+
export * from './utils/robots/typedef.js';
|
|
12
|
+
|
|
13
|
+
// Re-export sitemap typedefs
|
|
14
|
+
export * from './utils/sitemap/typedef.js';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create language utilities configured with your app config
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} config - Configuration object
|
|
5
|
+
* @param {Record<string, {lang: string, locale: string}>} config.languages
|
|
6
|
+
* Language configurations
|
|
7
|
+
* @param {string} config.defaultLanguage - Default language code
|
|
8
|
+
* @param {string} config.name - App name (for %title% injection)
|
|
9
|
+
* @param {string} config.description - App description
|
|
10
|
+
*
|
|
11
|
+
* @returns {{
|
|
12
|
+
* getLangFromPath: Function,
|
|
13
|
+
* injectLang: Function,
|
|
14
|
+
* handleLang: Function
|
|
15
|
+
* }}
|
|
16
|
+
*/
|
|
17
|
+
export function createLangUtils(config: {
|
|
18
|
+
languages: Record<string, {
|
|
19
|
+
lang: string;
|
|
20
|
+
locale: string;
|
|
21
|
+
}>;
|
|
22
|
+
defaultLanguage: string;
|
|
23
|
+
name: string;
|
|
24
|
+
description: string;
|
|
25
|
+
}): {
|
|
26
|
+
getLangFromPath: Function;
|
|
27
|
+
injectLang: Function;
|
|
28
|
+
handleLang: Function;
|
|
29
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create language utilities configured with your app config
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} config - Configuration object
|
|
5
|
+
* @param {Record<string, {lang: string, locale: string}>} config.languages
|
|
6
|
+
* Language configurations
|
|
7
|
+
* @param {string} config.defaultLanguage - Default language code
|
|
8
|
+
* @param {string} config.name - App name (for %title% injection)
|
|
9
|
+
* @param {string} config.description - App description
|
|
10
|
+
*
|
|
11
|
+
* @returns {{
|
|
12
|
+
* getLangFromPath: Function,
|
|
13
|
+
* injectLang: Function,
|
|
14
|
+
* handleLang: Function
|
|
15
|
+
* }}
|
|
16
|
+
*/
|
|
17
|
+
export function createLangUtils(config) {
|
|
18
|
+
const { languages, defaultLanguage, name, description } = config;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Extract language code from URL pathname
|
|
22
|
+
*
|
|
23
|
+
* @param {string} pathname - URL pathname (e.g., '/en/shop')
|
|
24
|
+
*
|
|
25
|
+
* @returns {{
|
|
26
|
+
* langCode: string,
|
|
27
|
+
* lang: string,
|
|
28
|
+
* locale: string
|
|
29
|
+
* }}
|
|
30
|
+
*/
|
|
31
|
+
function getLangFromPath(pathname) {
|
|
32
|
+
const match = pathname.match(/^\/([a-z]{2}(?:-[a-z]{2})?)\//i);
|
|
33
|
+
const langCode = match ? match[1].toLowerCase() : defaultLanguage;
|
|
34
|
+
|
|
35
|
+
const langConfig = languages[langCode] || languages[defaultLanguage];
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
langCode,
|
|
39
|
+
lang: langConfig.lang,
|
|
40
|
+
locale: langConfig.locale
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Transform HTML to inject language, title, and description
|
|
46
|
+
*
|
|
47
|
+
* @param {string} html - HTML string with placeholders
|
|
48
|
+
* @param {string} lang - Language code (e.g., 'en-GB')
|
|
49
|
+
*
|
|
50
|
+
* @returns {string} HTML with values injected
|
|
51
|
+
*/
|
|
52
|
+
function injectLang(html, lang) {
|
|
53
|
+
return html
|
|
54
|
+
.replace('%lang%', lang)
|
|
55
|
+
.replace('%title%', name)
|
|
56
|
+
.replace('%description%', description);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* SvelteKit hook handler for language detection
|
|
61
|
+
*
|
|
62
|
+
* @param {object} event - SvelteKit event object
|
|
63
|
+
* @param {Function} resolve - SvelteKit resolve function
|
|
64
|
+
*
|
|
65
|
+
* @returns {Promise<Response>}
|
|
66
|
+
*/
|
|
67
|
+
async function handleLang(event, resolve) {
|
|
68
|
+
const { langCode, lang, locale } = getLangFromPath(event.url.pathname);
|
|
69
|
+
|
|
70
|
+
event.locals.langCode = langCode;
|
|
71
|
+
event.locals.lang = lang;
|
|
72
|
+
event.locals.locale = locale;
|
|
73
|
+
|
|
74
|
+
return resolve(event, {
|
|
75
|
+
transformPageChunk: ({ html }) => injectLang(html, lang)
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
getLangFromPath,
|
|
81
|
+
injectLang,
|
|
82
|
+
handleLang
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { generateRobotsTxt, isHostAllowed } from "./robots/robots.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { generateRobotsTxt, isHostAllowed } from './robots/robots.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { generateSitemap } from "./sitemap/sitemap.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { generateSitemap } from './sitemap/sitemap.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Meta utilities for SEO, PWA, and favicons
|
|
3
|
+
*
|
|
4
|
+
* @module @hkdigital/lib-core/meta
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Language utilities
|
|
8
|
+
export { createLangUtils } from './utils/lang.js';
|
|
9
|
+
|
|
10
|
+
export { generateRobotsTxt, isHostAllowed } from './utils/robots.js';
|
|
11
|
+
export { generateSitemap } from './utils/sitemap.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hkdigital/lib-core",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.95",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "HKdigital",
|
|
6
6
|
"url": "https://hkdigital.nl"
|
|
@@ -41,13 +41,13 @@
|
|
|
41
41
|
"cache:clear": "rm -rf node_modules/.cache/imagetools",
|
|
42
42
|
"lint:prettier": "prettier --check .",
|
|
43
43
|
"lint:eslint": "eslint .",
|
|
44
|
-
"lint:imports": "node scripts/validate-imports.mjs",
|
|
44
|
+
"lint:imports": "node scripts/validate-imports.mjs --exclude src/lib/meta/templates",
|
|
45
45
|
"test:unit": "vitest",
|
|
46
46
|
"test:unit-run": "pnpm run test:unit -- --run",
|
|
47
47
|
"prepack:sync": "svelte-kit sync",
|
|
48
48
|
"prepack:build": "svelte-package",
|
|
49
49
|
"prepack:lint": "publint",
|
|
50
|
-
"prepack:imports": "node scripts/validate-imports.mjs",
|
|
50
|
+
"prepack:imports": "node scripts/validate-imports.mjs --exclude src/lib/meta/templates",
|
|
51
51
|
"publish:npm:version": "npm version patch",
|
|
52
52
|
"publish:npm:publish": "npm publish --access public",
|
|
53
53
|
"upgrade:hk:update": "ncu --dep dev,optional,peer,prod '@hkdigital/*' -u",
|
|
@@ -9,6 +9,27 @@ const SRC_DIR = join(PROJECT_ROOT, 'src');
|
|
|
9
9
|
const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url));
|
|
10
10
|
const LIB_ROOT = dirname(SCRIPT_DIR);
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Parse command line arguments for exclusion patterns
|
|
14
|
+
*
|
|
15
|
+
* @returns {string[]} Array of path patterns to exclude
|
|
16
|
+
*/
|
|
17
|
+
function parseExclusionArgs() {
|
|
18
|
+
const args = process.argv.slice(2);
|
|
19
|
+
const exclusions = [];
|
|
20
|
+
|
|
21
|
+
for (let i = 0; i < args.length; i++) {
|
|
22
|
+
if (args[i] === '--exclude' && i + 1 < args.length) {
|
|
23
|
+
exclusions.push(args[i + 1]);
|
|
24
|
+
i++; // Skip next arg since we consumed it
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return exclusions;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const EXCLUSION_PATTERNS = parseExclusionArgs();
|
|
32
|
+
|
|
12
33
|
/**
|
|
13
34
|
* Scopes to validate for barrel exports
|
|
14
35
|
* Any package under these scopes will be checked
|
|
@@ -555,6 +576,25 @@ async function findAliasBarrelExport(importPath, targetName) {
|
|
|
555
576
|
return null;
|
|
556
577
|
}
|
|
557
578
|
|
|
579
|
+
/**
|
|
580
|
+
* Check if file path matches any exclusion pattern
|
|
581
|
+
*
|
|
582
|
+
* @param {string} filePath - Path to check
|
|
583
|
+
*
|
|
584
|
+
* @returns {boolean} True if file should be excluded
|
|
585
|
+
*/
|
|
586
|
+
function isExcluded(filePath) {
|
|
587
|
+
const relativePath = relative(PROJECT_ROOT, filePath);
|
|
588
|
+
|
|
589
|
+
for (const pattern of EXCLUSION_PATTERNS) {
|
|
590
|
+
if (relativePath.includes(pattern)) {
|
|
591
|
+
return true;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
return false;
|
|
596
|
+
}
|
|
597
|
+
|
|
558
598
|
/**
|
|
559
599
|
* Validate import paths in a file
|
|
560
600
|
*
|
|
@@ -563,6 +603,11 @@ async function findAliasBarrelExport(importPath, targetName) {
|
|
|
563
603
|
* @returns {Promise<string[]>} Array of error messages
|
|
564
604
|
*/
|
|
565
605
|
async function validateFile(filePath) {
|
|
606
|
+
// Skip excluded files
|
|
607
|
+
if (isExcluded(filePath)) {
|
|
608
|
+
return [];
|
|
609
|
+
}
|
|
610
|
+
|
|
566
611
|
const content = await readFile(filePath, 'utf-8');
|
|
567
612
|
const errors = [];
|
|
568
613
|
const relativePath = relative(PROJECT_ROOT, filePath);
|
|
@@ -1234,6 +1279,12 @@ async function main() {
|
|
|
1234
1279
|
console.log(`Using script from @hkdigital/lib-core v${pkgJson.version}`);
|
|
1235
1280
|
console.log(`Validating import paths...`);
|
|
1236
1281
|
|
|
1282
|
+
if (EXCLUSION_PATTERNS.length > 0) {
|
|
1283
|
+
console.log('Excluding patterns:');
|
|
1284
|
+
EXCLUSION_PATTERNS.forEach(pattern => console.log(` ${pattern}`));
|
|
1285
|
+
console.log();
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1237
1288
|
// Load project aliases from svelte.config.js
|
|
1238
1289
|
PROJECT_ALIASES = await loadAliases();
|
|
1239
1290
|
|
package/dist/meta/robots.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { generateRobotsTxt, isHostAllowed } from "./robots/index.js";
|
package/dist/meta/robots.js
DELETED
package/dist/meta/sitemap.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { generateSitemap } from "./sitemap/index.js";
|
package/dist/meta/sitemap.js
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|