fimo-vite 2.11.0-staging.3 → 2.11.0-staging.5

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.
@@ -1,5 +1,6 @@
1
1
  import { readFileSync } from 'fs';
2
2
  import { resolveFimoConfigPath } from 'fimo/config';
3
+ import { resolveSiteUrl } from 'fimo/seo';
3
4
  const VIRTUAL_ID = 'virtual:fimo-config';
4
5
  const RESOLVED_ID = '\0' + VIRTUAL_ID;
5
6
  /**
@@ -32,7 +33,7 @@ export default function fimoConfigPlugin() {
32
33
  this.addWatchFile(configPath);
33
34
  try {
34
35
  const raw = readFileSync(configPath, 'utf-8');
35
- return `export default ${raw};`;
36
+ return `export default ${withPlatformSiteUrl(raw)};`;
36
37
  }
37
38
  catch {
38
39
  return 'export default {};';
@@ -57,6 +58,15 @@ export default function fimoConfigPlugin() {
57
58
  },
58
59
  };
59
60
  }
61
+ /** A browser cannot read `FIMO_SITE_URL`, so the build writes it into the config browser code imports. */
62
+ function withPlatformSiteUrl(raw) {
63
+ const url = resolveSiteUrl();
64
+ if (!url) {
65
+ return raw;
66
+ }
67
+ const config = JSON.parse(raw);
68
+ return JSON.stringify({ ...config, seo: { ...config.seo, url } });
69
+ }
60
70
  function readHtmlLang(configPath) {
61
71
  try {
62
72
  const raw = JSON.parse(readFileSync(configPath, 'utf-8'));
@@ -1,8 +1,8 @@
1
1
  import type { Plugin } from 'vite';
2
2
  /**
3
- * Emit a minimal `robots.txt` (allow-all + Sitemap reference if `seo.url` is
4
- * set in `.fimo/config.json`). Serves at `/robots.txt` in dev; emits as a
5
- * static asset at build time.
3
+ * Emit a minimal `robots.txt` (allow-all + Sitemap reference if the site has an
4
+ * address: `FIMO_SITE_URL`, else `seo.url` in `.fimo/config.json`). Serves at `/robots.txt` in dev; emits as a
5
+ * static asset at build time. A `public/robots.txt` in the project wins.
6
6
  *
7
7
  * Opt-in via `fimo({ robots: true })` in your `vite.config.ts`.
8
8
  */
@@ -1,15 +1,6 @@
1
- import { readFileSync } from 'fs';
2
- import { resolveFimoConfigPath } from 'fimo/config';
3
- function readSeoUrl() {
4
- try {
5
- const raw = readFileSync(resolveFimoConfigPath(process.cwd()), 'utf-8');
6
- const config = JSON.parse(raw);
7
- return config.seo?.url;
8
- }
9
- catch {
10
- return undefined;
11
- }
12
- }
1
+ import { existsSync } from 'fs';
2
+ import { join } from 'path';
3
+ import { readSeoUrl } from './site-url.js';
13
4
  function buildRobotsTxt(baseUrl) {
14
5
  const lines = ['User-agent: *', 'Allow: /'];
15
6
  if (baseUrl) {
@@ -24,18 +15,23 @@ function buildRobotsTxt(baseUrl) {
24
15
  return lines.join('\n') + '\n';
25
16
  }
26
17
  /**
27
- * Emit a minimal `robots.txt` (allow-all + Sitemap reference if `seo.url` is
28
- * set in `.fimo/config.json`). Serves at `/robots.txt` in dev; emits as a
29
- * static asset at build time.
18
+ * Emit a minimal `robots.txt` (allow-all + Sitemap reference if the site has an
19
+ * address: `FIMO_SITE_URL`, else `seo.url` in `.fimo/config.json`). Serves at `/robots.txt` in dev; emits as a
20
+ * static asset at build time. A `public/robots.txt` in the project wins.
30
21
  *
31
22
  * Opt-in via `fimo({ robots: true })` in your `vite.config.ts`.
32
23
  */
33
24
  export default function robotsPlugin() {
25
+ let publicDir = '';
26
+ const hasOwnFile = () => Boolean(publicDir) && existsSync(join(publicDir, 'robots.txt'));
34
27
  return {
35
28
  name: 'fimo:robots',
29
+ configResolved(config) {
30
+ publicDir = config.publicDir;
31
+ },
36
32
  configureServer(server) {
37
33
  server.middlewares.use((req, res, next) => {
38
- if (req.url?.split('?')[0] !== '/robots.txt') {
34
+ if (req.url?.split('?')[0] !== '/robots.txt' || hasOwnFile()) {
39
35
  next();
40
36
  return;
41
37
  }
@@ -45,6 +41,9 @@ export default function robotsPlugin() {
45
41
  });
46
42
  },
47
43
  generateBundle() {
44
+ if (hasOwnFile()) {
45
+ return;
46
+ }
48
47
  const baseUrl = readSeoUrl();
49
48
  this.emitFile({
50
49
  type: 'asset',
@@ -27,7 +27,8 @@ export default function seoPlugin() {
27
27
  const config = getConfigServer(rootDir);
28
28
  const pathname = normalizePathname(ctx?.path ?? '/');
29
29
  const seo = resolveSeoForPath(pathname, config);
30
- if (!seo) {
30
+ // An address alone gives this plugin nothing to write in place of the tags it strips.
31
+ if (!seo || !Object.entries(seo).some(([key, value]) => key !== 'url' && value !== undefined)) {
31
32
  return html;
32
33
  }
33
34
  let nextHtml = html;
@@ -0,0 +1,2 @@
1
+ export declare function readSeoUrl(): string | undefined;
2
+ //# sourceMappingURL=site-url.d.ts.map
@@ -0,0 +1,13 @@
1
+ import { readFileSync } from 'fs';
2
+ import { resolveFimoConfigPath } from 'fimo/config';
3
+ import { resolveSiteUrl } from 'fimo/seo';
4
+ export function readSeoUrl() {
5
+ try {
6
+ const raw = readFileSync(resolveFimoConfigPath(process.cwd()), 'utf-8');
7
+ const config = JSON.parse(raw);
8
+ return resolveSiteUrl(config.seo?.url);
9
+ }
10
+ catch {
11
+ return resolveSiteUrl();
12
+ }
13
+ }
@@ -1,16 +1,5 @@
1
- import { readFileSync } from 'fs';
2
- import { resolveFimoConfigPath } from 'fimo/config';
3
1
  import { getFimoPaths } from 'fimo/paths';
4
- function readSeoUrl() {
5
- try {
6
- const raw = readFileSync(resolveFimoConfigPath(process.cwd()), 'utf-8');
7
- const config = JSON.parse(raw);
8
- return config.seo?.url;
9
- }
10
- catch {
11
- return undefined;
12
- }
13
- }
2
+ import { readSeoUrl } from './site-url.js';
14
3
  function buildSitemapXml(baseUrl, paths) {
15
4
  const urls = paths
16
5
  .map((path) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fimo-vite",
3
- "version": "2.11.0-staging.3",
3
+ "version": "2.11.0-staging.5",
4
4
  "description": "Framework-neutral Fimo Vite plugin. Pairs with the fimo package at the same version.",
5
5
  "files": [
6
6
  "dist/",
@@ -31,16 +31,16 @@
31
31
  "oxc-parser": "^0.118.0"
32
32
  },
33
33
  "devDependencies": {
34
- "@fimo/tsconfig": "2.11.0-staging.3",
34
+ "@fimo/tsconfig": "2.11.0-staging.5",
35
35
  "@types/node": "22.18.6",
36
- "fimo": "2.11.0-staging.3",
36
+ "fimo": "2.11.0-staging.5",
37
37
  "typescript": "7.0.2",
38
38
  "vite": "8.3.5",
39
39
  "vite7": "npm:vite@^7.3.7",
40
40
  "vitest": "5.1.0"
41
41
  },
42
42
  "peerDependencies": {
43
- "fimo": "2.11.0-staging.3",
43
+ "fimo": "2.11.0-staging.5",
44
44
  "vite": "^7.0.0 || ^8.0.0"
45
45
  },
46
46
  "engines": {