mirror of
https://github.com/rustdesk/doc.rustdesk.com.git
synced 2026-08-29 13:20:36 +00:00
fix robots
This commit is contained in:
Vendored
+1
-47
@@ -1,12 +1,9 @@
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import type { AstroConfig, AstroIntegration } from 'astro';
|
||||
import type { AstroIntegration } from 'astro';
|
||||
|
||||
import configBuilder, { type Config } from './utils/configBuilder';
|
||||
import loadConfig from './utils/loadConfig';
|
||||
|
||||
export default ({ config: _themeConfig = 'src/config.yaml' } = {}): AstroIntegration => {
|
||||
let cfg: AstroConfig;
|
||||
return {
|
||||
name: 'astrowind-integration',
|
||||
|
||||
@@ -68,49 +65,6 @@ export default ({ config: _themeConfig = 'src/config.yaml' } = {}): AstroIntegra
|
||||
buildLogger.info(`Astrowind config has been loaded.`);
|
||||
}
|
||||
},
|
||||
'astro:config:done': async ({ config }) => {
|
||||
cfg = config;
|
||||
},
|
||||
|
||||
'astro:build:done': async ({ logger }) => {
|
||||
const buildLogger = logger.fork('astrowind');
|
||||
buildLogger.info('Updating `robots.txt` with `sitemap-index.xml` ...');
|
||||
|
||||
try {
|
||||
const outDir = cfg.outDir;
|
||||
const publicDir = cfg.publicDir;
|
||||
const sitemapName = 'sitemap-index.xml';
|
||||
const sitemapFile = new URL(sitemapName, outDir);
|
||||
const robotsTxtFile = new URL('robots.txt', publicDir);
|
||||
const robotsTxtFileInOut = new URL('robots.txt', outDir);
|
||||
|
||||
const hasIntegration =
|
||||
Array.isArray(cfg?.integrations) &&
|
||||
cfg.integrations?.find((e) => e?.name === '@astrojs/sitemap') !== undefined;
|
||||
const sitemapExists = fs.existsSync(sitemapFile);
|
||||
|
||||
if (hasIntegration && sitemapExists) {
|
||||
const robotsTxt = fs.readFileSync(robotsTxtFile, { encoding: 'utf8', flag: 'a+' });
|
||||
const sitemapUrl = new URL(sitemapName, String(new URL(cfg.base, cfg.site)));
|
||||
const pattern = /^Sitemap:(.*)$/m;
|
||||
|
||||
if (!pattern.test(robotsTxt)) {
|
||||
fs.writeFileSync(robotsTxtFileInOut, `${robotsTxt}${os.EOL}${os.EOL}Sitemap: ${sitemapUrl}`, {
|
||||
encoding: 'utf8',
|
||||
flag: 'w',
|
||||
});
|
||||
} else {
|
||||
fs.writeFileSync(robotsTxtFileInOut, robotsTxt.replace(pattern, `Sitemap: ${sitemapUrl}`), {
|
||||
encoding: 'utf8',
|
||||
flag: 'w',
|
||||
});
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
} catch (error) {
|
||||
/* empty */
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user