发布时间:2020-12-11
Z-Blog目前已经实现了首页和文章页的静态化,可以生成HTML文件,但是系统的分类页、标签Tags页、归档页和作者页都没有实现静态化,本文将讲述一个非常简单的方案,能够自动生成各个分类页、归档页和Tags的静态HTML页面,以便用户将网站迁移到Apache等不支持ASP的主机上。
Z-Blog的分类页、标签Tags页、归档页和作者页都是调用catalog.asp这个文件,因此,修改这个文件,当用户调用该文件的时候,自动生成针对该页面的HTML文件。如果访客反复读取这个文件,那么在一定时间范围内,可以直接在文件开头使用静态文件,以达到节省系统资源的目的。
具体的修改方法是,先在根下建立一个目录cat,然后使用编辑器打开Z-Blog根目录下的catalog.asp文件,在文件开头加入如下的代码:
Dim objFSO
Dim objFile
Dim strFileName
Dim strFileTime
Dim isBuildFile
if Request.QueryString("cate")<>"" then
if Request.QueryString("page")<>""then
strFileName = "cate" + "_" + Request.QueryString("cate") + "_" + Request.QueryString("page") +".html"
else
strFileName = "cate" + "_" + Request.QueryString("cate") + ".html"
end if
elseif Request.QueryString("tags")<>"" then
if Request.QueryString("page")<>""then
strFileName = "tags" + "_" + Request.QueryString("tags") + "_" + Request.QueryString("page") +".html"
else
strFileName = "tags" + "_" + Request.QueryString("tags") + ".html"
end if
elseif Request.QueryString("auth")<>"" then
if Request.QueryString("page")<>""then
strFileName = "auth" + "_" + Request.QueryString("auth") + "_" + Request.QueryString("page") +".html"
else
strFileName = "auth" + "_" + Request.QueryString("auth") + ".html"
end if
elseif Request.QueryString("date")<>"" then
if Request.QueryString("page")<>""then
strFileName = "date" + "_" + Request.QueryString("date") + "_" + Request.QueryString("page") +".html"
else
strFileName = "date" + "_" + Request.QueryString("date") + ".html"
end if
elseif Request.QueryString("page")<>"" then
strFileName = "default" + "_" + Request.QueryString("page") +".html"
else
strFileName = "default_1" + ".html"
end If
isBuildFile = False
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(Server.MapPath(strFileName)) Then
Set objFile = objFSO.GetFile(Server.MapPath(strFileName))
strFileTime = objFile.DateLastModified
Set objFile = Nothing
If datediff("h",strFileTime,Now()) > 1 Then
isBuildFile = True
Else
Server.Transfer strFileName
Response.End
End If
Else
isBuildFile = True
End If
Set objFSO = Nothing
Copyright © 2012-2021(tech.sysprice.com) 版权所有 Powered by 万站群
本站部份内容来源自网络,文字、素材、图片版权属于原作者,本站转载素材仅供大家欣赏和分享,切勿做为商业目的使用。
如果侵害了您的合法权益,请您及时与我们,我们会在第一时间删除相关内容!