@micazoyolli/foundation 0.3.1 → 0.4.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/LICENSE +21 -0
- package/README.md +39 -18
- package/dist/a11y/focus.js +17 -7
- package/dist/a11y/targets.js +2 -2
- package/dist/cli/deploy-github-pages.d.ts +2 -0
- package/dist/cli/deploy-github-pages.js +25 -0
- package/dist/git/githubPagesDeploy.d.ts +20 -0
- package/dist/git/githubPagesDeploy.js +176 -0
- package/dist/seo/dom.js +24 -14
- package/dist/seo/html.js +22 -18
- package/package.json +29 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nadia
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -3,17 +3,26 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@micazoyolli/foundation)
|
|
4
4
|
[](./LICENSE)
|
|
5
5
|
|
|
6
|
-
Fundamentos frontend no visuales para construir repos independientes con una base
|
|
6
|
+
Fundamentos frontend no visuales para construir repos independientes con una base técnica consistente.
|
|
7
7
|
|
|
8
|
-
Foundation centraliza
|
|
8
|
+
Foundation centraliza mecánicas pequeñas que se repiten entre proyectos: tokens SCSS base, mixins responsive, helpers TypeScript, primitivas DOM de accesibilidad y utilidades SEO/build. No incluye React, componentes visuales, tokens de marca, layouts ni metadata específica.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Documentation
|
|
11
11
|
|
|
12
|
-
La
|
|
12
|
+
La documentación principal vive en [foundation.nadia.dev](https://foundation.nadia.dev). Ahí está la guía completa, arquitectura, ejemplos, compatibilidad y referencia de la API.
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
## Features
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
- Tokens SCSS base: spacing, radius, z-index, motion y breakpoints.
|
|
17
|
+
- Mixins SCSS para responsive y reduced motion.
|
|
18
|
+
- `cx` y guards TypeScript pequeños.
|
|
19
|
+
- Helpers DOM para metadata client-side.
|
|
20
|
+
- Primitivas de accesibilidad para focus, Escape, scroll lock y media protegida.
|
|
21
|
+
- Helpers SEO/build para canonical, sitemap, HTML estático y escaping.
|
|
22
|
+
- CLI de build para publicar `dist` en GitHub Pages sin crear commits en la rama fuente.
|
|
23
|
+
- Sin dependencias runtime pesadas y sin React.
|
|
24
|
+
|
|
25
|
+
## Instalación
|
|
17
26
|
|
|
18
27
|
```bash
|
|
19
28
|
yarn add @micazoyolli/foundation
|
|
@@ -42,19 +51,19 @@ const canonical = getCanonicalUrl('https://example.com', '/contacto');
|
|
|
42
51
|
}
|
|
43
52
|
```
|
|
44
53
|
|
|
45
|
-
##
|
|
54
|
+
## Compatibilidad
|
|
46
55
|
|
|
47
|
-
|
|
48
|
-
- Mixins SCSS para responsive y reduced motion.
|
|
49
|
-
- `cx` y guards TypeScript pequenos.
|
|
50
|
-
- Helpers DOM para metadata client-side.
|
|
51
|
-
- Primitivas de accesibilidad para focus, Escape, scroll lock y media protegida.
|
|
52
|
-
- Helpers SEO/build para canonical, sitemap, HTML estatico y escaping.
|
|
53
|
-
- Sin dependencias runtime pesadas y sin React.
|
|
56
|
+
Foundation es framework agnostic y puede usarse con React, Next.js, Vue, Angular, Astro, Vite y Node según el helper utilizado.
|
|
54
57
|
|
|
55
|
-
##
|
|
58
|
+
## Resources
|
|
59
|
+
|
|
60
|
+
- Documentation: [foundation.nadia.dev](https://foundation.nadia.dev)
|
|
61
|
+
- GitHub: [github.com/micazoyolli/foundation](https://github.com/micazoyolli/foundation)
|
|
62
|
+
- npm: [npmjs.com/package/@micazoyolli/foundation](https://www.npmjs.com/package/@micazoyolli/foundation)
|
|
56
63
|
|
|
57
|
-
|
|
64
|
+
## Ecosistema
|
|
65
|
+
|
|
66
|
+
Foundation forma parte del ecosistema técnico de [`<micazoyolli />`](https://nadia.dev). La librería sostiene las piezas repetibles para que cada proyecto pueda conservar su propia identidad visual, contenido y experiencia.
|
|
58
67
|
|
|
59
68
|
## Scripts
|
|
60
69
|
|
|
@@ -64,6 +73,18 @@ yarn test
|
|
|
64
73
|
yarn docs:build
|
|
65
74
|
```
|
|
66
75
|
|
|
67
|
-
##
|
|
76
|
+
## CLI
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
micazoyolli-gh-pages-deploy
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
El CLI publica `dist` en `origin/gh-pages` desde un worktree temporal. Es tooling de build/deploy, no un export runtime.
|
|
83
|
+
|
|
84
|
+
## Autoría
|
|
85
|
+
|
|
86
|
+
Una creación de [`<micazoyolli />`](https://nadia.dev)
|
|
87
|
+
|
|
88
|
+
## Licencia
|
|
68
89
|
|
|
69
|
-
|
|
90
|
+
MIT
|
package/dist/a11y/focus.js
CHANGED
|
@@ -7,30 +7,40 @@ export const FOCUSABLE_SELECTOR = [
|
|
|
7
7
|
'textarea:not([disabled])',
|
|
8
8
|
'[tabindex]:not([tabindex="-1"])',
|
|
9
9
|
].join(',');
|
|
10
|
+
const getDocumentRef = (documentRef) => {
|
|
11
|
+
if (documentRef)
|
|
12
|
+
return documentRef;
|
|
13
|
+
if (typeof document !== 'undefined')
|
|
14
|
+
return document;
|
|
15
|
+
throw new ReferenceError('A document reference is required outside the browser.');
|
|
16
|
+
};
|
|
17
|
+
const getActiveElement = () => typeof document !== 'undefined' ? document.activeElement : undefined;
|
|
10
18
|
const canReceiveFocus = (element) => !element.disabled
|
|
11
19
|
&& element.getAttribute('aria-hidden') !== 'true'
|
|
12
20
|
&& element.tabIndex !== -1;
|
|
13
21
|
export const getFocusableElements = (container) => Array.from(container.querySelectorAll(FOCUSABLE_SELECTOR)).filter(canReceiveFocus);
|
|
14
|
-
export const lockBodyScroll = (documentRef
|
|
15
|
-
const
|
|
16
|
-
|
|
22
|
+
export const lockBodyScroll = (documentRef) => {
|
|
23
|
+
const currentDocument = getDocumentRef(documentRef);
|
|
24
|
+
const previousOverflow = currentDocument.body.style.overflow;
|
|
25
|
+
currentDocument.body.style.overflow = 'hidden';
|
|
17
26
|
return {
|
|
18
|
-
document:
|
|
27
|
+
document: currentDocument,
|
|
19
28
|
previousOverflow,
|
|
20
29
|
};
|
|
21
30
|
};
|
|
22
31
|
export const unlockBodyScroll = (lock) => {
|
|
23
32
|
lock.document.body.style.overflow = lock.previousOverflow;
|
|
24
33
|
};
|
|
25
|
-
export const restoreFocus = (element, documentRef
|
|
26
|
-
|
|
34
|
+
export const restoreFocus = (element, documentRef) => {
|
|
35
|
+
const currentDocument = getDocumentRef(documentRef);
|
|
36
|
+
if (!element || !currentDocument.body.contains(element))
|
|
27
37
|
return;
|
|
28
38
|
const focusable = element;
|
|
29
39
|
if (typeof focusable.focus === 'function') {
|
|
30
40
|
focusable.focus();
|
|
31
41
|
}
|
|
32
42
|
};
|
|
33
|
-
export const trapTabKey = (event, container, activeElement =
|
|
43
|
+
export const trapTabKey = (event, container, activeElement = getActiveElement()) => {
|
|
34
44
|
if (event.key !== 'Tab')
|
|
35
45
|
return false;
|
|
36
46
|
const focusableElements = getFocusableElements(container);
|
package/dist/a11y/targets.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const isElement = (target) => target instanceof Element;
|
|
2
|
-
export const isHTMLElement = (target) => target instanceof HTMLElement;
|
|
1
|
+
export const isElement = (target) => typeof Element !== 'undefined' && target instanceof Element;
|
|
2
|
+
export const isHTMLElement = (target) => typeof HTMLElement !== 'undefined' && target instanceof HTMLElement;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { deployGithubPages, GithubPagesDeployError } from '../git/githubPagesDeploy.js';
|
|
3
|
+
const main = async () => {
|
|
4
|
+
console.log('Deploying dist to origin/gh-pages...');
|
|
5
|
+
const result = await deployGithubPages();
|
|
6
|
+
if (!result.pushed) {
|
|
7
|
+
console.log(result.reason ?? 'No deployment commit was necessary.');
|
|
8
|
+
console.log('Repository left unchanged.');
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
console.log(`Published ${result.commit} to ${result.remote}/${result.deploymentBranch}.`);
|
|
12
|
+
console.log('Repository left clean on main.');
|
|
13
|
+
};
|
|
14
|
+
main().catch((error) => {
|
|
15
|
+
if (error instanceof GithubPagesDeployError) {
|
|
16
|
+
console.error(`Deployment failed: ${error.message}`);
|
|
17
|
+
}
|
|
18
|
+
else if (error instanceof Error) {
|
|
19
|
+
console.error(`Deployment failed: ${error.message}`);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
console.error('Deployment failed with an unknown error.');
|
|
23
|
+
}
|
|
24
|
+
process.exitCode = 1;
|
|
25
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type GithubPagesDeployOptions = {
|
|
2
|
+
buildDir?: string;
|
|
3
|
+
deploymentBranch?: string;
|
|
4
|
+
message?: string;
|
|
5
|
+
remote?: string;
|
|
6
|
+
sourceBranch?: string;
|
|
7
|
+
cwd?: string;
|
|
8
|
+
};
|
|
9
|
+
export type GithubPagesDeployResult = {
|
|
10
|
+
commit?: string;
|
|
11
|
+
deploymentBranch: string;
|
|
12
|
+
pushed: boolean;
|
|
13
|
+
reason?: string;
|
|
14
|
+
remote: string;
|
|
15
|
+
repositoryRoot: string;
|
|
16
|
+
};
|
|
17
|
+
export declare class GithubPagesDeployError extends Error {
|
|
18
|
+
constructor(message: string);
|
|
19
|
+
}
|
|
20
|
+
export declare const deployGithubPages: (options?: GithubPagesDeployOptions) => Promise<GithubPagesDeployResult>;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { cp, mkdtemp, readdir, rm, stat } from 'node:fs/promises';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { basename, join, resolve } from 'node:path';
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
5
|
+
const DEFAULT_BUILD_DIR = 'dist';
|
|
6
|
+
const DEFAULT_DEPLOYMENT_BRANCH = 'gh-pages';
|
|
7
|
+
const DEFAULT_MESSAGE = 'build: dist actualizado correctamente';
|
|
8
|
+
const DEFAULT_REMOTE = 'origin';
|
|
9
|
+
const DEFAULT_SOURCE_BRANCH = 'main';
|
|
10
|
+
export class GithubPagesDeployError extends Error {
|
|
11
|
+
constructor(message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = 'GithubPagesDeployError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const resolveOptions = (options = {}) => ({
|
|
17
|
+
buildDir: options.buildDir ?? DEFAULT_BUILD_DIR,
|
|
18
|
+
cwd: options.cwd ?? process.cwd(),
|
|
19
|
+
deploymentBranch: options.deploymentBranch ?? DEFAULT_DEPLOYMENT_BRANCH,
|
|
20
|
+
message: options.message ?? DEFAULT_MESSAGE,
|
|
21
|
+
remote: options.remote ?? DEFAULT_REMOTE,
|
|
22
|
+
sourceBranch: options.sourceBranch ?? DEFAULT_SOURCE_BRANCH,
|
|
23
|
+
});
|
|
24
|
+
const assertSafeGitRefPart = (value, label) => {
|
|
25
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._/-]*$/.test(value) || value.includes('..') || value.endsWith('/')) {
|
|
26
|
+
throw new GithubPagesDeployError(`Invalid ${label}: "${value}".`);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const runGit = (args, cwd) => {
|
|
30
|
+
const result = spawnSync('git', args, {
|
|
31
|
+
cwd,
|
|
32
|
+
encoding: 'utf8',
|
|
33
|
+
env: {
|
|
34
|
+
...process.env,
|
|
35
|
+
GIT_TERMINAL_PROMPT: '0',
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
if (result.error) {
|
|
39
|
+
throw new GithubPagesDeployError(`Failed to run git ${args.join(' ')}: ${result.error.message}`);
|
|
40
|
+
}
|
|
41
|
+
if (result.status !== 0) {
|
|
42
|
+
const details = (result.stderr || result.stdout || '').trim();
|
|
43
|
+
throw new GithubPagesDeployError(`Git command failed: git ${args.join(' ')}${details ? `\n${details}` : ''}`);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
stderr: result.stderr.trim(),
|
|
47
|
+
stdout: result.stdout.trim(),
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
const getRemoteTrackingRef = (remote, branch) => `refs/remotes/${remote}/${branch}`;
|
|
51
|
+
const fetchRemoteBranch = (repositoryRoot, remote, branch) => {
|
|
52
|
+
runGit(['fetch', remote, `+${branch}:${getRemoteTrackingRef(remote, branch)}`], repositoryRoot);
|
|
53
|
+
};
|
|
54
|
+
const getRepositoryRoot = (cwd) => {
|
|
55
|
+
try {
|
|
56
|
+
return runGit(['rev-parse', '--show-toplevel'], cwd).stdout;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
throw new GithubPagesDeployError('Current directory must be inside a Git repository.');
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const assertCleanWorkingTree = (repositoryRoot) => {
|
|
63
|
+
const status = runGit(['status', '--porcelain'], repositoryRoot).stdout;
|
|
64
|
+
if (status) {
|
|
65
|
+
throw new GithubPagesDeployError(`Working tree must be clean before deploying.\n${status}`);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const assertSyncedBranch = (repositoryRoot, sourceBranch, remote, deploymentBranch) => {
|
|
69
|
+
const currentBranch = runGit(['branch', '--show-current'], repositoryRoot).stdout;
|
|
70
|
+
if (currentBranch !== sourceBranch) {
|
|
71
|
+
throw new GithubPagesDeployError(`Current branch must be "${sourceBranch}". Found "${currentBranch || 'detached HEAD'}".`);
|
|
72
|
+
}
|
|
73
|
+
fetchRemoteBranch(repositoryRoot, remote, sourceBranch);
|
|
74
|
+
fetchRemoteBranch(repositoryRoot, remote, deploymentBranch);
|
|
75
|
+
const localHead = runGit(['rev-parse', sourceBranch], repositoryRoot).stdout;
|
|
76
|
+
const remoteHead = runGit(['rev-parse', `${remote}/${sourceBranch}`], repositoryRoot).stdout;
|
|
77
|
+
if (localHead !== remoteHead) {
|
|
78
|
+
throw new GithubPagesDeployError(`${sourceBranch} must be synchronized with ${remote}/${sourceBranch} before deploying.`);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const assertDeploymentBranchExists = (repositoryRoot, deploymentRef) => {
|
|
82
|
+
try {
|
|
83
|
+
runGit(['rev-parse', '--verify', `${deploymentRef}^{commit}`], repositoryRoot);
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
throw new GithubPagesDeployError(`Deployment branch "${deploymentRef}" must exist before deploying.`);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const assertBuildDirectory = async (buildDirectory) => {
|
|
90
|
+
let buildStat;
|
|
91
|
+
try {
|
|
92
|
+
buildStat = await stat(buildDirectory);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
throw new GithubPagesDeployError(`Build directory does not exist: ${buildDirectory}`);
|
|
96
|
+
}
|
|
97
|
+
if (!buildStat.isDirectory()) {
|
|
98
|
+
throw new GithubPagesDeployError(`Build path must be a directory: ${buildDirectory}`);
|
|
99
|
+
}
|
|
100
|
+
const entries = await readdir(buildDirectory);
|
|
101
|
+
if (entries.length === 0) {
|
|
102
|
+
throw new GithubPagesDeployError(`Build directory is empty: ${buildDirectory}`);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const clearWorktree = async (worktreePath) => {
|
|
106
|
+
const entries = await readdir(worktreePath);
|
|
107
|
+
await Promise.all(entries
|
|
108
|
+
.filter((entry) => entry !== '.git')
|
|
109
|
+
.map((entry) => rm(join(worktreePath, entry), {
|
|
110
|
+
force: true,
|
|
111
|
+
recursive: true,
|
|
112
|
+
})));
|
|
113
|
+
};
|
|
114
|
+
const cleanupWorktree = async (repositoryRoot, worktreePath, tempRoot) => {
|
|
115
|
+
try {
|
|
116
|
+
runGit(['worktree', 'remove', '--force', worktreePath], repositoryRoot);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
await rm(worktreePath, {
|
|
120
|
+
force: true,
|
|
121
|
+
recursive: true,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
await rm(tempRoot, {
|
|
125
|
+
force: true,
|
|
126
|
+
recursive: true,
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
export const deployGithubPages = async (options = {}) => {
|
|
130
|
+
const resolved = resolveOptions(options);
|
|
131
|
+
assertSafeGitRefPart(resolved.sourceBranch, 'source branch');
|
|
132
|
+
assertSafeGitRefPart(resolved.remote, 'remote');
|
|
133
|
+
assertSafeGitRefPart(resolved.deploymentBranch, 'deployment branch');
|
|
134
|
+
const repositoryRoot = getRepositoryRoot(resolved.cwd);
|
|
135
|
+
const buildDirectory = resolve(repositoryRoot, resolved.buildDir);
|
|
136
|
+
const deploymentRef = `${resolved.remote}/${resolved.deploymentBranch}`;
|
|
137
|
+
assertCleanWorkingTree(repositoryRoot);
|
|
138
|
+
assertSyncedBranch(repositoryRoot, resolved.sourceBranch, resolved.remote, resolved.deploymentBranch);
|
|
139
|
+
assertDeploymentBranchExists(repositoryRoot, deploymentRef);
|
|
140
|
+
await assertBuildDirectory(buildDirectory);
|
|
141
|
+
const tempRoot = await mkdtemp(join(tmpdir(), 'micazoyolli-gh-pages-'));
|
|
142
|
+
const worktreePath = join(tempRoot, basename(repositoryRoot));
|
|
143
|
+
try {
|
|
144
|
+
runGit(['worktree', 'add', '--detach', worktreePath, deploymentRef], repositoryRoot);
|
|
145
|
+
await clearWorktree(worktreePath);
|
|
146
|
+
await cp(buildDirectory, worktreePath, {
|
|
147
|
+
force: true,
|
|
148
|
+
recursive: true,
|
|
149
|
+
});
|
|
150
|
+
const deploymentStatus = runGit(['status', '--porcelain'], worktreePath).stdout;
|
|
151
|
+
if (!deploymentStatus) {
|
|
152
|
+
return {
|
|
153
|
+
deploymentBranch: resolved.deploymentBranch,
|
|
154
|
+
pushed: false,
|
|
155
|
+
reason: 'Deployment content is unchanged.',
|
|
156
|
+
remote: resolved.remote,
|
|
157
|
+
repositoryRoot,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
runGit(['add', '--all'], worktreePath);
|
|
161
|
+
runGit(['commit', '-m', resolved.message], worktreePath);
|
|
162
|
+
const commit = runGit(['rev-parse', '--short', 'HEAD'], worktreePath).stdout;
|
|
163
|
+
runGit(['push', resolved.remote, `HEAD:${resolved.deploymentBranch}`], worktreePath);
|
|
164
|
+
fetchRemoteBranch(repositoryRoot, resolved.remote, resolved.deploymentBranch);
|
|
165
|
+
return {
|
|
166
|
+
commit,
|
|
167
|
+
deploymentBranch: resolved.deploymentBranch,
|
|
168
|
+
pushed: true,
|
|
169
|
+
remote: resolved.remote,
|
|
170
|
+
repositoryRoot,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
finally {
|
|
174
|
+
await cleanupWorktree(repositoryRoot, worktreePath, tempRoot);
|
|
175
|
+
}
|
|
176
|
+
};
|
package/dist/seo/dom.js
CHANGED
|
@@ -1,34 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
documentRef
|
|
1
|
+
const getDocumentRef = (documentRef) => {
|
|
2
|
+
if (documentRef)
|
|
3
|
+
return documentRef;
|
|
4
|
+
if (typeof document !== 'undefined')
|
|
5
|
+
return document;
|
|
6
|
+
throw new ReferenceError('A document reference is required outside the browser.');
|
|
3
7
|
};
|
|
4
|
-
export const
|
|
5
|
-
|
|
8
|
+
export const updateDocumentTitle = (title, documentRef) => {
|
|
9
|
+
getDocumentRef(documentRef).title = title;
|
|
10
|
+
};
|
|
11
|
+
export const upsertMeta = (selector, attributes, documentRef) => {
|
|
12
|
+
const currentDocument = getDocumentRef(documentRef);
|
|
13
|
+
let element = currentDocument.head.querySelector(selector);
|
|
6
14
|
if (!element) {
|
|
7
|
-
element =
|
|
8
|
-
|
|
15
|
+
element = currentDocument.createElement('meta');
|
|
16
|
+
currentDocument.head.appendChild(element);
|
|
9
17
|
}
|
|
10
18
|
Object.entries(attributes).forEach(([name, value]) => {
|
|
11
19
|
element?.setAttribute(name, value);
|
|
12
20
|
});
|
|
13
21
|
return element;
|
|
14
22
|
};
|
|
15
|
-
export const upsertCanonical = (href, documentRef
|
|
16
|
-
|
|
23
|
+
export const upsertCanonical = (href, documentRef) => {
|
|
24
|
+
const currentDocument = getDocumentRef(documentRef);
|
|
25
|
+
let element = currentDocument.head.querySelector('link[rel="canonical"]');
|
|
17
26
|
if (!element) {
|
|
18
|
-
element =
|
|
27
|
+
element = currentDocument.createElement('link');
|
|
19
28
|
element.rel = 'canonical';
|
|
20
|
-
|
|
29
|
+
currentDocument.head.appendChild(element);
|
|
21
30
|
}
|
|
22
31
|
element.href = href;
|
|
23
32
|
return element;
|
|
24
33
|
};
|
|
25
|
-
export const upsertAlternate = (hreflang, href, documentRef
|
|
26
|
-
|
|
34
|
+
export const upsertAlternate = (hreflang, href, documentRef) => {
|
|
35
|
+
const currentDocument = getDocumentRef(documentRef);
|
|
36
|
+
let element = currentDocument.head.querySelector(`link[rel="alternate"][hreflang="${hreflang}"]`);
|
|
27
37
|
if (!element) {
|
|
28
|
-
element =
|
|
38
|
+
element = currentDocument.createElement('link');
|
|
29
39
|
element.rel = 'alternate';
|
|
30
40
|
element.hreflang = hreflang;
|
|
31
|
-
|
|
41
|
+
currentDocument.head.appendChild(element);
|
|
32
42
|
}
|
|
33
43
|
element.href = href;
|
|
34
44
|
return element;
|
package/dist/seo/html.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { escapeHtml } from './text.js';
|
|
1
2
|
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
2
3
|
const insertBeforeHeadEnd = (html, tag) => html.includes('</head>') ? html.replace('</head>', ` ${tag}\n </head>`) : html;
|
|
4
|
+
const getMetaTag = (name, content) => `<meta name="${name}" content="${escapeHtml(content)}" />`;
|
|
5
|
+
const getPropertyMetaTag = (property, content) => `<meta property="${property}" content="${escapeHtml(content)}" />`;
|
|
6
|
+
const getLinkTag = (rel, href, attributes = '') => `<link rel="${rel}"${attributes} href="${escapeHtml(href)}" />`;
|
|
3
7
|
export const upsertMetaTag = (html, selector, tag) => {
|
|
4
8
|
const pattern = new RegExp(`<meta\\s+${escapeRegExp(selector)}[^>]*>`);
|
|
5
9
|
if (pattern.test(html)) {
|
|
@@ -16,46 +20,46 @@ export const upsertLinkTag = (html, selector, tag) => {
|
|
|
16
20
|
};
|
|
17
21
|
export const removeAlternateLinks = (html) => html.replace(/\s*<link\s+rel="alternate"\s+hreflang="[^"]+"\s+href="[^"]+"\s*\/?>\n?/g, '');
|
|
18
22
|
export const getAlternateLinkTags = (alternates) => alternates
|
|
19
|
-
.map(({ href, hreflang }) =>
|
|
23
|
+
.map(({ href, hreflang }) => getLinkTag('alternate', href, ` hreflang="${escapeHtml(hreflang)}"`))
|
|
20
24
|
.join('\n ');
|
|
21
25
|
export const applyHtmlMetadata = (html, metadata, alternates = []) => {
|
|
22
26
|
let next = html;
|
|
23
27
|
if (metadata.lang) {
|
|
24
|
-
next = next.replace(/<html\s+lang="[^"]*">/, `<html lang="${metadata.lang}">`);
|
|
28
|
+
next = next.replace(/<html\s+lang="[^"]*">/, `<html lang="${escapeHtml(metadata.lang)}">`);
|
|
25
29
|
}
|
|
26
30
|
if (metadata.title) {
|
|
27
|
-
next = next.replace(/<title>[\s\S]*?<\/title>/, `<title>${metadata.title}</title>`);
|
|
28
|
-
next = upsertMetaTag(next, 'name="title"',
|
|
29
|
-
next = upsertMetaTag(next, 'property="og:title"',
|
|
30
|
-
next = upsertMetaTag(next, 'name="twitter:title"',
|
|
31
|
+
next = next.replace(/<title>[\s\S]*?<\/title>/, `<title>${escapeHtml(metadata.title)}</title>`);
|
|
32
|
+
next = upsertMetaTag(next, 'name="title"', getMetaTag('title', metadata.title));
|
|
33
|
+
next = upsertMetaTag(next, 'property="og:title"', getPropertyMetaTag('og:title', metadata.title));
|
|
34
|
+
next = upsertMetaTag(next, 'name="twitter:title"', getMetaTag('twitter:title', metadata.title));
|
|
31
35
|
}
|
|
32
36
|
if (metadata.description) {
|
|
33
|
-
next = upsertMetaTag(next, 'name="description"',
|
|
34
|
-
next = upsertMetaTag(next, 'property="og:description"',
|
|
35
|
-
next = upsertMetaTag(next, 'name="twitter:description"',
|
|
37
|
+
next = upsertMetaTag(next, 'name="description"', getMetaTag('description', metadata.description));
|
|
38
|
+
next = upsertMetaTag(next, 'property="og:description"', getPropertyMetaTag('og:description', metadata.description));
|
|
39
|
+
next = upsertMetaTag(next, 'name="twitter:description"', getMetaTag('twitter:description', metadata.description));
|
|
36
40
|
}
|
|
37
41
|
if (metadata.canonical) {
|
|
38
|
-
next = upsertMetaTag(next, 'property="og:url"',
|
|
39
|
-
next = upsertLinkTag(next, 'rel="canonical"',
|
|
42
|
+
next = upsertMetaTag(next, 'property="og:url"', getPropertyMetaTag('og:url', metadata.canonical));
|
|
43
|
+
next = upsertLinkTag(next, 'rel="canonical"', getLinkTag('canonical', metadata.canonical));
|
|
40
44
|
}
|
|
41
45
|
if (metadata.image) {
|
|
42
|
-
next = upsertMetaTag(next, 'property="og:image"',
|
|
43
|
-
next = upsertMetaTag(next, 'name="twitter:image"',
|
|
46
|
+
next = upsertMetaTag(next, 'property="og:image"', getPropertyMetaTag('og:image', metadata.image));
|
|
47
|
+
next = upsertMetaTag(next, 'name="twitter:image"', getMetaTag('twitter:image', metadata.image));
|
|
44
48
|
}
|
|
45
49
|
if (metadata.robots) {
|
|
46
|
-
next = upsertMetaTag(next, 'name="robots"',
|
|
50
|
+
next = upsertMetaTag(next, 'name="robots"', getMetaTag('robots', metadata.robots));
|
|
47
51
|
}
|
|
48
52
|
if (metadata.siteName) {
|
|
49
|
-
next = upsertMetaTag(next, 'property="og:site_name"',
|
|
53
|
+
next = upsertMetaTag(next, 'property="og:site_name"', getPropertyMetaTag('og:site_name', metadata.siteName));
|
|
50
54
|
}
|
|
51
55
|
if (metadata.ogImageWidth) {
|
|
52
|
-
next = upsertMetaTag(next, 'property="og:image:width"',
|
|
56
|
+
next = upsertMetaTag(next, 'property="og:image:width"', getPropertyMetaTag('og:image:width', String(metadata.ogImageWidth)));
|
|
53
57
|
}
|
|
54
58
|
if (metadata.ogImageHeight) {
|
|
55
|
-
next = upsertMetaTag(next, 'property="og:image:height"',
|
|
59
|
+
next = upsertMetaTag(next, 'property="og:image:height"', getPropertyMetaTag('og:image:height', String(metadata.ogImageHeight)));
|
|
56
60
|
}
|
|
57
61
|
if (metadata.twitterCard) {
|
|
58
|
-
next = upsertMetaTag(next, 'name="twitter:card"',
|
|
62
|
+
next = upsertMetaTag(next, 'name="twitter:card"', getMetaTag('twitter:card', metadata.twitterCard));
|
|
59
63
|
}
|
|
60
64
|
if (alternates.length > 0) {
|
|
61
65
|
next = removeAlternateLinks(next);
|
package/package.json
CHANGED
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micazoyolli/foundation",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Fundamentos frontend no visuales para el ecosistema
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Fundamentos frontend no visuales para el ecosistema técnico de Nad.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"homepage": "https://foundation.nadia.dev",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/micazoyolli/foundation.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/micazoyolli/foundation/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"frontend",
|
|
17
|
+
"design-tokens",
|
|
18
|
+
"scss",
|
|
19
|
+
"accessibility",
|
|
20
|
+
"seo",
|
|
21
|
+
"typescript",
|
|
22
|
+
"vitepress"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=20"
|
|
26
|
+
},
|
|
7
27
|
"main": "dist/index.js",
|
|
8
28
|
"types": "dist/index.d.ts",
|
|
29
|
+
"bin": {
|
|
30
|
+
"micazoyolli-gh-pages-deploy": "dist/cli/deploy-github-pages.js"
|
|
31
|
+
},
|
|
9
32
|
"exports": {
|
|
10
33
|
".": {
|
|
11
34
|
"import": "./dist/index.js",
|
|
@@ -22,16 +45,18 @@
|
|
|
22
45
|
"access": "public"
|
|
23
46
|
},
|
|
24
47
|
"scripts": {
|
|
25
|
-
"build": "tsc -p tsconfig.json && yarn copy-scss",
|
|
48
|
+
"build": "tsc -p tsconfig.json && node scripts/mark-cli-executable.mjs && yarn copy-scss",
|
|
26
49
|
"clean": "rm -rf dist",
|
|
27
50
|
"copy-scss": "rsync -av --include='*/' --include='*.scss' --exclude='*' src/scss/ dist/scss/",
|
|
28
|
-
"docs:build": "vitepress build docs",
|
|
51
|
+
"docs:build": "yarn build && node scripts/generate-docs-seo.mjs && vitepress build docs",
|
|
29
52
|
"docs:dev": "vitepress dev docs --host 0.0.0.0",
|
|
30
53
|
"docs:preview": "vitepress preview docs --host 0.0.0.0",
|
|
31
54
|
"prepack": "yarn build",
|
|
32
55
|
"test": "yarn build && node --test tests/*.test.mjs"
|
|
33
56
|
},
|
|
34
57
|
"devDependencies": {
|
|
58
|
+
"@types/node": "24.10.4",
|
|
59
|
+
"sass-embedded": "^1.100.0",
|
|
35
60
|
"typescript": "6.0.3",
|
|
36
61
|
"vitepress": "^1.6.4"
|
|
37
62
|
},
|