A+ Sitemap生成器说明书

 

A+ Sitemap生成器说明书

本文地址:http://blog.csdn.net/aimeast/archive/2009/02/19/3911971.aspx

下载地址:http://download.csdn.net/source/1025534

 

本程序具有以下特点:

支持所有的动态系统

能够根据不同的论坛、Blog系统动态的生成Sitemap。支持动态、静态页面的生成。

 

具有丰富的配置文件。

可针对不同的页面设置不同的changefreqpriority等值。每个组件都有独立的配置。

 

生成速度快

不需要遍历整个网站就能生成Sitemap。中型论坛可以在不到10秒钟就生成整个Sitemap。更加节省了网络带宽、降低了服务器负荷。

 

扩展性强

运用设计模式,具有非常好的可扩展性。可以随意的增改组件。

 

程序的目录结构

Sitemap

  Global.asax

  MakeSitemap.aspx                              手动生成器

  Sitemap.config                                      全局配置文件

  Sitemap.txt                                            生成好的Txt格式的Sitemap

  Sitemap.txt.aspx                                  显示Sitemap.txt

  Sitemap.xml                                           生成好的Xml格式的Sitemap

  Sitemap.xml.aspx                                 显示Sitemap.xml

  web.config                                             

├─App_Code

      Sitemap_BbsDB.cs                     动态生成组件

      Sitemap_Exception.cs                异常定义

      Sitemap_Mange.cs                     所有的框架和管理类

      Sitemap_StaticList.cs                 静态列表生成组件

└─App_Data

        SitemapBbsDbList.xml               动态生成组件的配置文件

        SitemapStaticList.txt                静态列表生成组件的配置文件

 

进行配置

/Sitemap.config

<?xml version="1.0" encoding="utf-8" ?>

<SitemapConfig><!-- 配置的根节点 -->

  <Ver>0.1</Ver><!-- 版本号必须为0.1 -->

  <Format FilePath="Sitemap.xml">Xml</Format><!-- 保存一个Sitemap.xmlXml格式 -->

  <Format FilePath="Sitemap.txt">Text</Format><!-- 保存一个Sitemap.txtText格式 -->

  <AutoMake>True</AutoMake><!-- 是否启用自动生成 可选值为 True|False -->

  <IngoreComponentException>True</IngoreComponentException><!-- 当一个组件出现错误时,是否忽略错误 可选值为 True|False -->

  <Maker>

    <!-- 组件的单独配置 必须要有版本,其他参数为自定义参数 -->

    <StaticList><!-- 组件的类的名称 必须与代码中的一样 -->

      <Ver>0.1</Ver><!-- 版本号 -->

      <FilePath>App_Data/SitemapStaticList.txt</FilePath><!-- 静态列表保存的相对路径 不能使用MapPath.”“~等标记 -->

      <LastModDateTime>Auto</LastModDateTime><!-- 最后修改时间 auto为列表的最后修改时间 -->

      <ChangeFreq>monthly</ChangeFreq><!-- 改变频率 -->

      <Priority>0.5</Priority><!-- 重要系数 -->

    </StaticList>

    <BbsDB>

      <Ver>0.1</Ver><!-- 版本号 -->

      <DbType>Access</DbType><!-- 数据库类型 -->

      <ConnStr>Provider=Microsoft.Jet.OleDb.4.0;Data Source=F:/Work/Inetpub/yo612.cn/www/App_Data/dznt_db.mdb;Persist Security Info=True;</ConnStr><!-- 数据库连接串 -->

      <FilePath>App_Data/SitemapBbsDbList.xml</FilePath><!-- 生成方法的相对路径 不能使用MapPath.”“~等标记 -->

    </BbsDB>

  </Maker>

</SitemapConfig>

 

/App_Data/ SitemapStaticList.txt

保存Url,每行一个。

 

/App_Data/SitemapBbsDbList.xml(部分)

<?xml version="1.0" encoding="utf-8" ?>

<BbsDbList><!-- 根节点 -->

  <Group changefreq="always" priority="1" table="" field="" where="">

    <!-- table是要查询的表 field是要查询的字段 目前只支持一个字段 where是查询的条件 可以为空 -->

    <Item>http://www.yo612.cn/dznt/</Item><!-- Item是使用这以查询的url。参数用String.Format格式化字符串表示 -->

    <Item>http://www.yo612.cn/dznt/index.aspx</Item>

  </Group>

  <Group changefreq="always" priority="0.9" table="dnt_forums" field="fid" where="">

    <Item>http://www.yo612.cn/dznt/archiver/showforum-{0}.aspx</Item>

  </Group>

  <Group changefreq="daily" priority="0.85" table="dnt_topics" field="tid" where="">

    <Item>http://www.yo612.cn/dznt/archiver/showtopic-{0}.aspx</Item>

    <Item>http://www.yo612.cn/dznt/showtopic-{0}.aspx</Item>

  </Group>

  <Group changefreq="monthly" priority="0.8" table="dnt_users" field="uid" where="">

    <Item>http://www.yo612.cn/dznt/userinfo-{0}.aspx</Item>

  </Group>

</BbsDbList>

 

使用方法

所有文件按照上述目录结构保存,在Global.asax文件的void Application_Start(object sender, EventArgs e)事件中加入SitemapManage.GetInstance();,作用是根据Sitemap.config的设置决定是否自动生成Sitemap。也可以执行MakeSitemap.aspx手动生成。

 

组件编写方法

继承并实现SitemapMaker抽象类,框架如下

using System;

using Sitemap;

 

public class My_Component : SitemapMaker

{

    public override void LoadConfig(System.Xml.XmlNode config)

    {

        throw new NotImplementedException();

    }

    public override void Process()

    {

        throw new NotImplementedException();

    }

    public override URLCollection GetURLCollection()

    {

        throw new NotImplementedException();

    }

}

然后在Sitemap.config中加入My_Component的配置

Maker中加入如下内容

    <My_Component>

      <Ver>0.0</Ver>

      <SomeConfigs></SomeConfigs>

    </My_Component>

这样就完成了组件的编写。

 

附言

程序自带的BbsDB类没有实现其他数据库。要实现其他的数据库只要继承并实现BbsDbDataHelper即可。

打包文件里面的配置是Discuz!NT 2.5.0的常用Uri

由于编写时间仓促,自带的配置(主要是SitemapBbsDbList.xml)有不完整的地方。使用时请自行修改。(现在Google已经报告说有无法访问的连接了)

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值