广告联盟网

 找回密码
 注册
查看: 820|回复: 0
打印 上一主题 下一主题

下载生成XML的Google SiteMap代码的ASP文件

[复制链接]
跳转到指定楼层
1#
发表于 2005-11-29 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
<%
Server.ScriptTimeout=50000
dim seoDir
session(&quot;server&quot;)=&quot;http://www.seo165.com&quot;     '网址
seoDir=&quot;/&quot;

set objfso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
root = Server.MapPath(seoDir)

'response.ContentType = &quot;text/xml&quot;
'response.write &quot;<?xml version='1.0' encoding='UTF-8'?>&quot;
'response.write &quot;<urlset xmlns='http://www.google.com/schemas/sitemap/0.84'>&quot;

str = &quot;<?xml version='1.0' encoding='UTF-8'?>&quot; & vbcrlf
str = str & &quot;<urlset xmlns='http://www.google.com/schemas/sitemap/0.84'>&quot; & vbcrlf

Set objFolder = objFSO.GetFolder(root)
'response.write getfilelink(objFolder.Path,objFolder.dateLastModified)
Set colFiles = objFolder.Files
For Each objFile In colFiles
str=str & getfilelink(objFile.Path,objfile.dateLastModified) & vbcrlf
Next
ShowSubFolders(objFolder)


str = str & &quot;</urlset>&quot; & vbcrlf
set fso = nothing

Set objStream = Server.CreateObject(&quot;ADODB.Stream&quot;)
With objStream
.Open
.Charset = &quot;utf-8&quot;
.Position = objStream.Size
.WriteText=str
.SaveToFile server.mappath(&quot;/sitemap.xml&quot;),2 '生成的XML文件名
.Close
End With

Set objStream = Nothing
If Not Err Then
Response.Write(&quot;<script>alert('成功生成站点地图!');history.back();</script>&quot;)
Response.End
End If

Sub ShowSubFolders(objFolder)
Set colFolders = objFolder.SubFolders
For Each objSubFolder In colFolders
if folderpermission(objSubFolder.Path) then
str = str & getfilelink(objSubFolder.Path,objSubFolder.dateLastModified) & vbcrlf
Set colFiles = objSubFolder.Files
For Each objFile In colFiles
str = str & getfilelink(objFile.Path,objFile.dateLastModified) & vbcrlf
Next
ShowSubFolders(objSubFolder)
end if
Next
End Sub


Function getfilelink(file,datafile)
file=replace(file,root,&quot;&quot;)
file=replace(file,&quot;\&quot;,&quot;/&quot;)
If FileExtensionIsBad(file) then Exit Function
if month(datafile)<10 then filedatem=&quot;0&quot;
if day(datafile)<10 then filedated=&quot;0&quot;
filedate=year(datafile)&&quot;-&quot;&filedatem&month(datafile)&&quot;-&quot;&filedated&day(datafile)
getfilelink = &quot;<url><loc>&quot;&server.htmlencode(session(&quot;server&quot;)&seoDir&file)&&quot;</loc><lastmod>&quot;&filedate&&quot;</lastmod><changefreq>daily</changefreq><priority>1.0</priority></url>&quot;
Response.Flush
End Function


Function Folderpermission(pathName)
PathExclusion=Array(&quot;\temp&quot;,&quot;\_vti_cnf&quot;,&quot;_vti_pvt&quot;,&quot;_vti_log&quot;,&quot;cgi-bin&quot;,&quot;\admin&quot;,&quot;\edu&quot;)
Folderpermission =True
for each PathExcluded in PathExclusion
if instr(ucase(pathName),ucase(PathExcluded))>0 then
Folderpermission = False
exit for
end if
next
End Function


Function FileExtensionIsBad(sFileName)
Dim sFileExtension, bFileExtensionIsValid, sFileExt
Extensions = Array(&quot;png&quot;,&quot;gif&quot;,&quot;jpg&quot;,&quot;jpeg&quot;,&quot;zip&quot;,&quot;pdf&quot;,&quot;ps&quot;,&quot;html&quot;,&quot;htm&quot;,&quot;php&quot;,&quot;wk1&quot;,&quot;wk2&quot;,&quot;wk3&quot;,&quot;wk4&quot;,&quot;wk5&quot;,&quot;wki&quot;,&quot;wks&quot;,&quot;wku&quot;,&quot;lwp&quot;,&quot;mw&quot;,&quot;xls&quot;,&quot;ppt&quot;,&quot;doc&quot;,&quot;swf&quot;,&quot;wks&quot;,&quot;wps&quot;,&quot;wdb&quot;,&quot;wri&quot;,&quot;rtf&quot;,&quot;ans&quot;,&quot;txt&quot;,&quot;asp&quot;)
'设置列表的文件名,扩展名不在其中的话SiteMap则不会收录该扩展名的文件

if len(trim(sFileName)) = 0 then
FileExtensionIsBad=true
Exit Function
end if

sFileExtension = right(sFileName, len(sFileName) - instrrev(sFileName, &quot;.&quot;))
bFileExtensionIsValid=false
for each sFileExt in extensions
if ucase(sFileExt)=ucase(sFileExtension) then
bFileExtensionIsValid=True
exit for
end if
next
FileExtensionIsBad = not bFileExtensionIsValid
End Function
%>

[ Last edited by ycccf on 2005-12-7 at 08:10 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|广告联盟网  

GMT, 2024-5-13 , Processed in 0.042653 second(s), 19 queries .

Powered by Discuz! X3.2

© 2005-2021 www.ggads.com GGADS 广告联盟网

快速回复 返回顶部 返回列表