Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
开发云
开源百科(首页)
提交
8981d88a
开源百科(首页)
项目概览
开发云
/
开源百科(首页)
通知
26
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
开源百科(首页)
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
8981d88a
编写于
4月 01, 2022
作者:
李少辉-开发者
🎧
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add sitemap path to robots txt
Signed-off-by:
lish
<
lish@csdn.net
>
上级
33830078
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
21 addition
and
3 deletion
+21
-3
public/robots.txt
public/robots.txt
+2
-1
public/sitemap.xml
public/sitemap.xml
+4
-0
sitemap-merge.js
sitemap-merge.js
+15
-2
未找到文件。
public/robots.txt
浏览文件 @
8981d88a
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
public/sitemap.xml
浏览文件 @
8981d88a
...
...
@@ -8,4 +8,8 @@
<loc>
https://docs.gitcode.net/spring/guide/sitemap.xml
</loc>
<lastmod>
"2022-04-01T10:27:44.390Z"
</lastmod>
</sitemap>
<sitemap>
<loc>
https://docs.gitcode.net/spring/guide/sitemap.xml
</loc>
<lastmod>
"2022-04-01T10:45:44.701Z"
</lastmod>
</sitemap>
</sitemapindex>
\ No newline at end of file
sitemap-merge.js
浏览文件 @
8981d88a
...
...
@@ -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
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录