octfx/wiki-seo

允许对每页进行元设置,如关键词和描述,更改标题和各种网站验证标签。

安装量: 1,607

依赖: 0

建议者: 0

安全: 0

星标: 6

关注者: 19

分支: 7

类型:mediawiki-extension

v2.7.0 2023-06-29 09:12 UTC

README

从2023-01-23开始,WikiSEO需要MediaWiki 1.39.0

WikiSEO扩展允许您替换、追加或预置html标题标签的内容,并允许您添加常见的SEO元关键词和元描述。

扩展页面: Extension:WikiSEO

安装

  • 下载并将文件放置在您的extensions/文件夹中名为WikiSEO的目录中。
  • 在您的LocalSettings.php底部添加以下代码
wfLoadExtension( 'WikiSEO' );
  • 根据需要配置。
  • 完成 – 导航到您的维基中的Special:Version以验证扩展是否成功安装。

配置

以下变量由该扩展使用。

用法

扩展可以通过{{#seo}}解析函数或通过使用mw.ext.seo在Lua模块中使用。它接受以下命名字段,顺序不限。

  • title
    • 您希望在html标题标签中出现的标题
  • title_mode
    • 设置为追加、预置或替换(默认)以定义如何修改标题。
  • title_separator
    • 如果titlemode设置为追加或预置,则分隔符;“ - ”(默认)
  • keywords
    • 元关键词标签的关键词逗号分隔列表
  • description
    • 元描述标签的文本描述
  • robots
    • 控制搜索引擎爬取和索引的行为
    • 假定以下顺序:索引策略,跟进策略
    • 示例:robots=index,nofollow / noindex,follow / index,follow / 等。
    • 无效:robots=follow,index
  • googlebot
    • 控制谷歌爬虫的行为
  • hreflang_xx-xx[]
    • 添加<link rel="alternate" href="url" hreflang="xx-xx">元素 +*规范
    • 添加<link rel="canonical" href="url">元素

与Open Graph协议相关的标签

  • type
    • 您的对象类型,例如,“video.movie”。根据您指定的类型,可能还需要其他属性。
  • image
    • 表示您对象内的图像URL。如果设置了图像名称作为参数,扩展将自动添加正确的图像URL、宽度和高度。示例 image = Local_file_to_use.png。或者可以使用完整的图像URL,然后将image_width和image_height手动设置。如果没有设置参数,则扩展将使用$wgLogo作为后备或通过$wgWikiSeoDefaultImage设置的本地文件。
  • image_width
    • px中的图像宽度。(如果设置了图像,则自动设置)
  • image_height
    • px中的图像高度。(如果设置了图像,则自动设置)
  • image_alt
    • 图像的替代描述。
  • locale
    • 标记这些标签的语言区域。格式为language_TERRITORY。
  • site_name
    • 如果您的对象是大型网站的一部分,则应显示的网站名称。例如,“IMDb”。

与Open Graph类型“文章”相关的标签

  • author
    • 文章的作者。
  • keywords
    • 转换为文章:tag
  • section
    • 高级部分名称。例如,技术
  • published_time
    • 文章首次发布的时间。ISO 8601格式。

与Twitter Cards相关的标签(参见OpenGraph标签)

  • twitter_site
    • 如果您未通过$wgTwitterSiteHandle设置全局站点名称,您可以按页面设置站点名称。如果设置了全局站点名称,则此键将被忽略。
  • twitter_card
    • 允许按页面覆盖$wgWikiSEOTwitterCardType

与引文生成器相关的标签

  • description
  • keywords
  • citation_author
  • citation_conference_title
  • citation_creation_date(之前为citation_date_created)
  • citation_doi
  • citation_firstpage(之前为citation_page_start)
  • citation_headline
  • citation_isbn
  • citation_issn
  • citation_issue
  • citation_journal_title
  • citation_lastpage
  • citation_license
  • citation_name
  • citation_pdf_url
  • citation_publication_date(之前为citation_date_published)
  • citation_publisher
  • citation_title
  • citation_type
  • citation_volume

多个作者应通过;分隔。

** 与Dublin Core生成器相关的标签**

  • description
  • title
  • author
  • locale
  • site_name
  • dc.identifier.wikidata

示例

添加静态值

{{#seo:
 |title=Your page title
 |titlemode=append
 |keywords=these,are,your,keywords
 |description=Your meta description
 |image=Uploaded_file.png
 |image_alt=Wiki Logo
}}

添加动态值

如果您需要包含变量或模板,应使用解析器函数以确保它们被正确解析。这允许您使用Cargo或Semantic MediaWiki、页面表单进行数据录入,或从现有变量或内容创建页面标题...

{{#seo:
 |title={{#if: {{{page_title|}}} | {{{page_title}}} | Welcome to WikiSEO}}
 |titlemode={{{title_mode|}}}
 |keywords={{{keywords|}}}
 |description={{{description|}}}
 |published_time={{REVISIONYEAR}}-{{REVISIONMONTH}}-{{REVISIONDAY2}}
}}
{{#seo:
|title_mode=append
|title=Example SEO Wiki
|keywords=WikiSEO, SEO, MediaWiki
|description=An example description for this wiki
|image=Wiki_Logo.png
|image_alt=Wiki Logo
|site_name=Example SEO Wiki
|locale=en_EN
|type=website
|modified_time={{REVISIONYEAR}}-{{REVISIONMONTH}}-{{REVISIONDAY2}}
|published_time=2020-11-01
}}

使用lua模块

WikiSEO以mw.ext.seo.set的形式公开lua方法

示例模块

-- Module:SEO
local seo = {}

--[[
argTable format:
{
  title_mode = 'append',
  title = 'Example Seo Wiki',
  keywords = 'WikiSEO, SEO, MediaWiki',
  -- ...
}
]]--
function seo.set( argTable )
  mw.ext.seo.set( argTable )
end

function seo.setStatic()
  mw.ext.seo.set{
    title_mode = 'append',
    title = 'Example Seo Wiki',
    keywords = 'WikiSEO, SEO, MediaWiki',  
  }
end

return seo

现在该模块可以通过以下方式调用:{{#invoke:SEO|add|title=ExampleTitle|keywords=WikiSEO, SEO, MediaWiki}}{{#invoke:SEO|addStatic}}

Hreflang属性

{{#seo:
 |hreflang_de-de=https://example.de/page
 |hreflang_nl-nl=https://example.nl/page-nl
 |hreflang_en-us=https://website.com/
}}

将生成以下<link>元素

<link rel="alternate" href="https://example.de/page" hreflang="de-de">
<link rel="alternate" href="https://example.nl/page-nl" hreflang="nl-nl">
<link rel="alternate" href="https://website.com/" hreflang="en-us">

标题模式

示例:标题为Example Page的页面

附加

{{#seo:
 |title_mode=append
 |title=Appended Title
}}

HTML标题结果:Example Page - Appended Title

前置

{{#seo:
 |title_mode=prepend
 |title=Prepended Title
}}

HTML标题结果:Prepended Title - Example Page

前置(更改分隔符)

{{#seo:
 |title_mode=prepend
 |title=Prepended Title
 |title_separator=<nowiki>&nbsp;>>&nbsp;</nowiki>
}}

HTML标题结果:Prepended Title >> Example Page

替换(默认)

{{#seo:
 |title_mode=replace
 |title=Replaced Title
}}

HTML标题结果:Replaced Title

钩子

WikiSEO公开钩子,允许自定义添加到页面并保存到页面属性中的元数据。

  • WikiSEOPreAddMedatada
    • onWikiSEOPreAddMedatada( &$metadata )
    • 通过Validator::validateParams验证过的键值对数组
    • 在元数据生成器实例化之前运行
  • WikiSEOPreAddPageProps
    • onWikiSEOPreAddPageProps( &$metadata )
    • 通过Validator::validateParams验证过的键值对数组
    • 在设置页面属性之前运行
  • WikiSEOLuaPreAddPageProps
    • onWikiSEOLuaPreAddPageProps( &$metadata )
    • 通过Validator::validateParams验证过的键值对数组
    • 在设置页面属性之前运行
    • 仅当调用lua模块时运行 | $wgWikiSeoSocialImageBackgroundColor = #14181f; |

迁移到v2

已删除标签

  • DC.date.created
  • DC.date.issued
  • google
  • name
  • og:title(自动设置)
  • og:url(自动设置)
  • twitter:card(自动设置)
  • twitter:creator
  • twitter:domain
  • article:modified_time / og:updated_time(自动设置)

已删除别名

  • metakeywords / metak
    • 使用关键词代替
  • metadescription / metad
    • 使用描述代替
  • titlemode / title mode
    • 使用title_mode代替

更改参数名称

  • article:author -> author
  • article:section -> section
  • article:tag -> keywords
  • article:published_time -> published_time
  • og:image / twitter:image:src -> image
  • og:image:width -> image_width
  • og:image:height -> image_height
  • og:locale -> locale
  • og:site_name -> site_name
  • og:title -> title
  • og:type -> type
  • twitter:description -> description

已知问题

Extension:PageImages将在页面找到图像时添加og:image标签。这将覆盖使用此扩展设置的任何og:image标签。
目前无法禁用PageImages设置元标签。

备注

如果您只想在页面上覆盖显示标题(而不是向其中添加单词),您还可以查看与 Manual:$wgAllowDisplayTitleManual:$wgRestrictDisplayTitle 设置组合使用的 DISPLAYTITLE 标签。

schema.org

SchemaOrg 生成器将根据 Special:Search 设置 SearchAction 属性。
属性发布者和作者将被设置为组织,名称设置为 $wgSitename 的内容。
dateModified 将通过获取最新修订时间戳自动设置。如果没有设置 published_time,datePublished 将设置为最新修订时间戳。

OpenGraph

article:modified_time 将通过获取最新修订时间戳自动设置。如果没有设置 published_timearticle:published_time 将设置为最新修订时间戳。
这可以通过在解析器中设置 modified_time=- 来在每页的基础上禁用。

扩展此扩展

元数据生成器位于 includes/Generator/Plugins 目录。
生成器必须实现 GeneratorInterface
要加载生成器,只需将其名称添加到 $wgMetadataGenerators