Jump to content

扩展:AutoSitemap(站点地图自动化)

From mediawiki.org
This page is a translated version of the page Extension:AutoSitemap and the translation is 46% complete.
MediaWiki扩展手册
AutoSitemap
发行状态: 稳定版
实现 MyWiki , 页面操作
描述 每当站内任一页面发生变化时,创建或更新站点地图文件(sitemap.xml)。
作者 Dolfinus, François Boutines-Vignard, Jehy, Thomas
最新版本 1.8.2 (2024-10-29)
MediaWiki 1.28+
数据库更改
许可协议 GNU通用公眾授權條款3.0或更新版本
下載
README
示例 已生成的站点地图
$wgAutoSitemap

AutoSitemap 扩展会在每次页面创建、编辑或删除时自动生成一个 sitemap.xml 文件。 Sitemap 文件可以帮助搜索引擎更好地抓取你站点的页面。 该扩展基于 ManualSitemap 扩展。

原因

由于托管服务商的限制,我无法通过调度器(例如 cron)更新 sitemap,而且我也不想手动更新它。

因此,我修改了一个现有的扩展,让它在任何页面编辑、创建、删除、重命名、上传等事件发生时自动更新 sitemap。

注意

该扩展适用于小型 MediaWiki 实例(最多约 1 万页)。 如果你的实例超过 5 万页,建议使用 GenerateSitemap.php ,因为它支持:sitemap 索引文件、为每个命名空间生成独立文件、压缩 sitemap 文件、设计为通过调度器定期运行,而不是在每次页面修改后触发。

安裝

  • 下载文件,并将其放置在您extensions/文件夹中的AutoSitemap目录内。
  • 請新增下列代码到您的LocalSettings.php 文件的底部:
    wfLoadExtension( 'AutoSitemap' );
    
  • 让你的 wiki 页面产生任何变化,例如创建一个新页面或更新一个已有页面。
  • Sitemap 文件将会自动生成。
  • Yes 完成 – 請导航至您的wiki上的Special:Version,以验证此扩展已成功安装。

配置

有一些可选的参数,用于改变 sitemap 的生成方式。 可以在 LocalSettings.php 里设置它们。

文件名

可以通过以下设置为 sitemap 文件配置文件名:

$wgAutoSitemap["filename"] = "sitemap.xml"; //default value

设置根 URL

By default all URLs in sitemap use $wgCanonicalServer (or $wgServer, if it doesn’t set) as domain prefix. If you want to set it to another one, you can change it manually by setting:

$wgAutoSitemap["server"] = "https://your-site.com";

Exclude types of pages from sitemap

You can exclude namespaces or exact pages from including them to sitemap:

$wgAutoSitemap["exclude_namespaces"] = [
    NS_TALK,
    NS_USER,   
    NS_USER_TALK,
    NS_PROJECT_TALK,
    NS_FILE_TALK,
    NS_MEDIAWIKI,   
    NS_MEDIAWIKI_TALK,
    NS_TEMPLATE,
    NS_TEMPLATE_TALK,
    NS_HELP,   
    NS_HELP_TALK,
    NS_CATEGORY_TALK
]; //default values

$wgAutoSitemap["exclude_pages"] = ['page title to exclude', 'other one'];

If you need to exclude custom namespace from sitemap, pass here namespace ID (integer) instead of name constant.


Set page update frequency

You can manually specify the recommended frequency with which all addresses will be checked by search engine:

$wgAutoSitemap["freq"] = "daily"; //default

Available values are:

hourly
daily
weekly
monthly
yearly
adjust - for automatic determination of frequency based on page edits count

Set page priority

You can manually specify priority for certain pages or namespaces:

$wgAutoSitemap["priority"] = 0.7;

or

$wgAutoSitemap["priority"][NS_MAIN] = 1;
$wgAutoSitemap["priority"][NS_CATEGORY] = 0.8;

or

$wgAutoSitemap["priority"]['Main page'] = 1;
$wgAutoSitemap["priority"]['Other page'] = 0.8;

Rate-limit recreation of the sitemap

For wikis with many pages, generating the sitemap may consume significant resources, so you may not want it to happen too frequently. With this option, you can specify that the sitemap should only be recreated if it's at least a certain number of seconds old.

$wgAutoSitemap["min_age"] = 3600; // 1 hour, default 0 (no rate-limit)

Use

Blank page after installing extension

Please follow Manual:如何调试 instruction to get exception message interrupting page render process. Usually this is caused by passing undefined constant to $wgAutoSitemap["exclude_namespaces"].

Permissions

Your MediaWiki folder should be permitted for write operations (chmod +w with chown apache or chown nginx).

Htaccess, Nginx

If you want to see a human-readable sitemap, allow read access for sitemap.xsl file in your site config (.htaccess file or other).

See also