diff --git a/public/robots.txt b/public/robots.txt index 8d2417a6bb9a8da39e58c290bd99a745df8b7826..f90d2c5497fdaadb8a0d69d9f95cfda82c99e474 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -1,4 +1,5 @@ User-agent: * Allow:/ -Sitemap: https://docs.gitcode.net/sitemap.xml \ No newline at end of file +Sitemap: https://docs.gitcode.net/sitemap.xml +Sitemap: https://docs.gitcode.net/spring/guide/sitemap.xml \ No newline at end of file diff --git a/public/sitemap.xml b/public/sitemap.xml index 2f33c2d77195f1506ed6a1267dac9d2f942d47bd..6e30b95042fb841607daa6cb0da2723e948c8fa9 100644 --- a/public/sitemap.xml +++ b/public/sitemap.xml @@ -8,4 +8,8 @@ https://docs.gitcode.net/spring/guide/sitemap.xml "2022-04-01T10:27:44.390Z" + + https://docs.gitcode.net/spring/guide/sitemap.xml + "2022-04-01T10:45:44.701Z" + \ No newline at end of file diff --git a/sitemap-merge.js b/sitemap-merge.js index 07c2a99cb0679b7b136bd77c97bfc0440de92908..5b8647bce2913eacf31331dcce4f9c05c496a0eb 100644 --- a/sitemap-merge.js +++ b/sitemap-merge.js @@ -5,6 +5,7 @@ const builder = new xml2js.Builder(); const sitemap_path = "./public/sitemap.xml" +const robot_path = "./public/robots.txt" const allowed_sitemaps = [ 'https://docs.gitcode.net/spring/guide/sitemap.xml' @@ -12,7 +13,7 @@ const allowed_sitemaps = [ // 读取xml 文件内容 -function get_sitemap_content(sitemap_path){ +function get_file_content(sitemap_path){ return fs.readFileSync(sitemap_path) } // 解析xml @@ -37,7 +38,18 @@ function write_to_file(path, content){ fs.writeFileSync(path, content) } -var sitemap_string = get_sitemap_content(sitemap_path) +function check_robot(){ + var robot_string = get_file_content(robot_path).toString() + console.log(robot_string) + allowed_sitemaps.forEach(function(item){ + if(robot_string.indexOf(item)<0){ + robot_string = robot_string + "\n" + "Sitemap: " + item + } + }) + write_to_file(robot_path, robot_string) +} + +var sitemap_string = get_file_content(sitemap_path) parse_sitemap_content(sitemap_string).then(function(sitemap_json){ allowed_sitemaps.forEach(function(item){ @@ -49,6 +61,7 @@ parse_sitemap_content(sitemap_string).then(function(sitemap_json){ return build_sitemap_from_json_content(sitemap_json) }).then(function(xml){ write_to_file(sitemap_path, xml) + check_robot() console.log('Done') }).catch(function(err){ console.log(err)