Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

secure hidden pages #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions index_plus.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ async function handlerRequest(event){
k = await handle_admin(request);
break;
case "article": //文章内容页
k = await handle_article(paths[1]);
k = await handle_article(paths);
break;
case "": //文章 首页
case "page": //文章 分页
Expand All @@ -239,7 +239,7 @@ async function handlerRequest(event){
headers:{
"content-type":"text/html;charset=UTF-8"
},
status:200
status:404
})
break;
}
Expand Down Expand Up @@ -498,7 +498,8 @@ async function renderBlog(url){
}

//渲染前端博客的文章内容页
async function handle_article(id){
async function handle_article(paths){
let id = paths[1];
//获取内容页模板源码
let theme_html=await getThemeHtml("article"),
//KV中读取导航栏、分类目录、标签、链接、近期文章等配置信息
Expand All @@ -517,6 +518,17 @@ async function handle_article(id){
//获取本篇文章
let article=articles_sibling[1];

// 当文章为隐藏时id后面的文章永久地址不匹配直接404
if (article.hidden) {
if (!(paths[2] && paths[2] === article.link))
return new Response(OPT.html404,{
headers:{
"content-type":"text/html;charset=UTF-8"
},
status:404
});
}

//组装文章详情页各参数
let title=article.title.replace(nullToEmpty(OPT.top_flag),'').replace(nullToEmpty(OPT.hidden_flag),'')+" - "+OPT.siteName,
keyWord=article.tags.concat(article.category).join(","),
Expand Down