米扑科技旗下的产品,近期正在做SEO网站优化,其中子需求之一是调研实现了网站地图(sitemap.xml)

封装简化了许多功能模块,现在分享出来,源代码可在Github上下载,有简单的示例。

Github 开源网址sitemap-php

What is sitemap-php ?

sitemap-php 是一个轻量级、简单快速生成网站地图的开源项目,由北京米扑科技有限公司(mimvp.com)开发分享。

通过简单的配置定义,一个函数createSitemap(),可自动生成sitemap.xml、sitemap.html等网站地图文件,

自动生成的xml、html文件,支持Google、Bing、Baidu等主流搜索引擎收录。

Fast and lightweight class for generating Google sitemap XML files and index of sitemap files.

Written on PHP and uses XMLWriter extension (wrapper for libxml xmlWriter API) for creating XML files. XMLWriter extension is enabled by default in PHP 5 >= 5.1.2.

If you having more than 50000 url, it splits items to seperated files. (In benchmarks, 1.000.000 url was generating in 8 seconds)

示例:

sitemap.xml : http://mimvp.com/sitemap.xml

sitemap.html : http://mimvp.com/sitemap.html

How to use

Sitemap 封装了生成sitemap.xml的属性和方法的类,使用非常简单,示例代码:

function testSitemap() {
$sitemap = new Sitemap("http://mimvp.com"); $sitemap->addItem('/', '1.0', 'daily', 'Today');
$sitemap->addItem('/hr.php', '0.8', 'monthly', time());
$sitemap->addItem('/index.php', '1.0', 'daily', 'Jun 25');
$sitemap->addItem('/about.php', '0.8', 'monthly', '2017-06-26'); $sitemap->addItem('/hr2.php', '1.0', 'daily', time())->addItem('/index2.php', '1.0', 'daily', 'Today')->addItem('/about2.php', '0.8', 'monthly', 'Jun 25'); $sitemap->endSitemap();
}
  1. 初始化类对象
$sitemap = new Sitemap("http://mimvp.com");
  1. 添加Item
$sitemap->addItem('/', '1.0', 'daily', 'Today');
$sitemap->addItem('/hr.php', '0.8', 'monthly', time());
$sitemap->addItem('/index.php', '1.0', 'daily', 'Jun 25');
$sitemap->addItem('/about.php', '0.8', 'monthly', '2017-06-26');

或者

$sitemap->addItem('/hr2.php', '1.0', 'daily', time())->addItem('/index2.php', '1.0', 'daily', 'Today')->addItem('/about2.php', '0.8', 'monthly', 'Jun 25');
  1. 结束文档
$sitemap->endSitemap();
  1. 生成结果 sitemap.xml
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://mimvp.com/</loc>
<priority>1.0</priority>
<changefreq>daily</changefreq>
<lastmod>2017-06-26T00:00:00+08:00</lastmod>
</url>
<url>
<loc>http://mimvp.com/hr.php</loc>
<priority>0.8</priority>
<changefreq>monthly</changefreq>
<lastmod>2017-06-26T20:16:23+08:00</lastmod>
</url>
<url>
<loc>http://mimvp.com/index.php</loc>
<priority>1.0</priority>
<changefreq>daily</changefreq>
<lastmod>2017-06-25T00:00:00+08:00</lastmod>
</url>
<url>
<loc>http://mimvp.com/about.php</loc>
<priority>0.8</priority>
<changefreq>monthly</changefreq>
<lastmod>2017-06-26T00:00:00+08:00</lastmod>
</url>
</urlset>

More Functions

  1. 设置根域名
$sitemap = new Sitemap("http://mimvp.com");

也可以修改初始化的域名为

$sitemap->setDomain('http://blog.mimvp.com');
  1. 设置保存路径 sitemap.xml默认保存在当前目录下,也可设置文件夹目录,例如: xmls/sitemap,表示sitemap.xml保存在当前目录下的xmls/目录下,其中xmls目录会自动创建。注:支持多级目录
$sitemap->setXmlFile("xmls/sitemap");
$sitemap->setXmlFile("xmls/mimvp/sitemap");
  1. 设置是否更多头部
$sitemap->setIsChemaMore(true);

如果设置为true,则sitemap.xml文件头部会增加一些头部信息:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
  1. 获取当前写入的sitemap文件
$sitemap->getCurrXmlFileFullPath();

Advanced Functions

  1. 指定包含文件,以/开头
$GIncludeArray = array("", "/index.php", "about.php", "hr.php");
  1. 排除特定文件或目录
$GExcludeArray = array("usercenter/", "sadmin/", "admin/", "sitemap.php");
  1. 递归扫描指定目录,默认扫描三层(可自己设定)
function scanRootPath($rootPath=".", $dirLevel=1, $MaxDirLevel=3, &$resArray=array())
  1. 转化 xml + xsl 为 html
function createXSL2Html($xmlFile, $xslFile, $htmlFile, $isopen_htmlfile=false) 

Sitemap Demo

  1. 全局变量,G开头
$GCONFIG = array(	"domain"=>"http://mimvp.com",
"xmlfile"=>"sitemap",
"htmlfile"=>"sitemap.html",
"xslfile"=>"sitemap-xml.xsl",
"isopen_xmlfile"=>true,
"isopen_htmlfile"=>true,
"isscanrootpath"=>true,
"isxsl2html"=>true,
"isschemamore"=>true);
  1. 生成sitemap.xml
createSitemap();

生成示例:

  1. 生成 sitemap.html
createXSL2Html($xmlFile, $xslFile, $htmlFile, $isopen_htmlfile=false);

生成示例:

You need to submit sitemap.xml and sitemap.html to Google、 Bing、 Baidu,etc.

sitemap-php项目,目前支持指定网页、排除网页、扫描根目录等网站地图;
后期完善时,会增加导出数据库、爬取整个网站等功能,
也希望您的加入,继续完善此项目

sitemap-php All Rights by mimvp.com

米扑科技的开源项目:sitemap-php 自动生成网站地图的更多相关文章

  1. 讲解开源项目:用 Python 生成有“灵魂”的二维码

    本文作者:HelloGitHub-LITTLECHIEH 这是 HelloGitHub 推出的<讲解开源项目>系列,今天给大家推荐一个 Python 开源生成二维码的项目--qrcode ...

  2. 开源项目使用 appveyor 自动构建

    我写了几个开源项目,我想要有小伙伴提交的时候自动运行单元测试,自动运行编译,这样可以保证小伙伴提交清真的代码 本文将会告诉大家如何接入 appveyor 自动构建方案,在 Github 上给自己的开源 ...

  3. Go 语言,开源服务端代码自动生成 框架 - EasyGoServer

    EasyGoServer 作者:林冠宏 / 指尖下的幽灵 掘金:https://juejin.im/user/587f0dfe128fe100570ce2d8 博客:http://www.cnblog ...

  4. sphinx:python项目文档自动生成

    Sphinx: 发音: DJ音标发音: [sfiŋks] KK音标发音: [sfɪŋks] 单词本身释义: an ancient imaginary creature with a lion's bo ...

  5. 泰晓科技 +兰大开源社区 +程序动态分析---LINUX内核网站

    http://www.tinylab.org/ http://linux-talents.tinylab.org/lzuoss/ http://www.tinylab.org/source-code- ...

  6. 开源:C# 代码自动生成工具,支持站点前后台

    前言 写这个项目有很长一段时间了,期间也修修改改,写到最后,自己也没咋用(研究方向变化了). 正文 具体项目开源了:https://github.com/supperlitt/WebAutoCodeO ...

  7. Discuz开源论坛本地部署自动生成数据库

    这个版本可能比较有点老,但是万变不离其宗,再新的版本都是在已有的基础上更新的,所以掌握方法是最重要的! 先上几张安装成功后的图 (安装成功的论坛首页) (后台管理登录页) 下面说一下安装步骤 第一步: ...

  8. maven项目使用mybatis-generator自动生成代码

    1.添加mybatis-generator插件,打开pom.xml文件 在project节点下添加: <build> <plugins> <!-- MyBatis代码生成 ...

  9. 在idea中,mavne项目使用mybatis-generator-maven-plugin自动生成实体了的时候,在maven插件里面始终不显示

    最近想学习mybatis的知识,自己搭了个简单的ssm框架,想通过插件自动生成实体类,发现想要的插件一直都没显示出来,着实很郁闷: pom.xm中的配置: <!--mybatis-generat ...

随机推荐

  1. P2727 Stringsobits

    01串 Stringsobits 题目背景 考虑排好序的N(N<=31)位二进制数. 题目描述 他们是排列好的,而且包含所有长度为N且这个二进制数中1的位数的个数小于等于L(L<=N)的数 ...

  2. python webserver, based on SimpleHTTPServer

    #-*- coding:utf-8 -*- #author: lichmama #email: nextgodhand@163.com #filename: httpd.py import io im ...

  3. @RequestParam与@PathVariable的区别

    在spring MVC中,两者的作用都是将request里的参数的值绑定到contorl里的方法参数里的,区别在于,URL写法不同. 使用@RequestParam时,URL是这样的:http://h ...

  4. 微信iOS消息拦截插件教程-Tweak HelloWorld

    微信iOS消息拦截插件教程-Tweak HelloWorld 标签(空格分隔): 越狱开发教程 1.环境准备 准备一台越狱的手机,具体参照上一篇教程 搭建Theos越狱开发环境 2.开发过程 新建一个 ...

  5. js实现日期格式化

    <!DOCTYPE html><html><head> <meta charset="utf-8"> <meta http-e ...

  6. JVM学习001通过实例总结Java虚拟机的运行机制

    JVM学习(1)——通过实例总结Java虚拟机的运行机制-转载http://www.cnblogs.com/kubixuesheng/p/5199200.html 文章转载自:http://www.c ...

  7. data-packed volume container - 每天5分钟玩转 Docker 容器技术(43)

    在上一节的例子中 volume container 的数据归根到底还是在 host 里,有没有办法将数据完全放到 volume container 中,同时又能与其他容器共享呢? 当然可以,通常我们称 ...

  8. nyoj_600:花儿朵朵(树状数组+坐标离散化)

    http://acm.nyist.net/JudgeOnline/problem.php?pid=600 只附代码好了 #include<bits/stdc++.h> using name ...

  9. 1、微信小程序----弹幕的实现(无后台)

    小程序刚刚出来,现在网上的demo是多,但是要找到一个自己需要的却不容易.今天跟大家分享自己写的一个弹幕功能. 先来一张效果图: 我的思路是这样的,先用<switch>标签确定是否打开弹幕 ...

  10. tensorflow max_pool(最大池化)应用

    1.最大池化 max pooling是CNN当中的最大值池化操作,其实用法和卷积很类似. tf.nn.max_pool(value, ksize, strides, padding, name=Non ...