Advanced SEO measures-automatic setting of title tag and description

By default, Giblog has effective SEO measures implemented.

Automatic setting of title tag

The title of the top page "index.html" will be the site title set in "site_title" of giblog.conf.

use strict;
use warnings;
use utf8;

{
  site_title =>'My original site',
  site_url =>'http://somesite.example',
}

In this case, the title tag of the top page will be "My original site".

<title> My own original site </title>

Titles other than the top page will have the site title after the first heading on the page.

An example of a page other than the top page is, for example, the first heading

<h2> How to eat delicious tomatoes </h2>

If so, the title tag on this page will be "How to Eat Tomatoes-My Original Site".

<title> How to eat delicious tomatoes-my original site </title>

Automatic description setting

The first untagged paragraph is automatically set to description.

<h2> How to eat delicious tomatoes </h2>

How can I eat tomatoes deliciously? Let's cool it in the refrigerator.
<meta name = "description" content = "How can I eat tomatoes deliciously? Let's cool them in the refrigerator.">

The first paragraph with a tag is not recognized as a description, so you can also write a breadcrumb trail that is important for SEO.

<ol class = "bread" itemscope itemtype = "http://schema.org/BreadcrumbList">
  <li itemprop = "itemListElement" itemscope itemtype = "http://schema.org/ListItem">
    <a itemprop="item" href="/"> <span itemprop = "name"> tomato </span></a>
    <meta itemprop = "position" content = "1" />
  </li>
  & # 8250;
  <li itemprop = "itemListElement" itemscope itemtype = "http://schema.org/ListItem">
    <a itemprop="item" href="/blog/20101130129876.html"> <span itemprop = "name"> How to eat </span></a>
    <meta itemprop = "position" content = "2" />
  </li>
  & # 8250;
  <li itemprop = "itemListElement" itemscope itemtype = "http://schema.org/ListItem">
      <span itemprop = "name"> here </span>
  </li>
</ol>

<h2> How to eat delicious tomatoes </h2>

How can I eat tomatoes deliciously? Let's cool it in the refrigerator.

As mentioned above, even if you have a breadcrumb trail, the content of the first untagged paragraph is set to description.

<meta name = "description" content = "How can I eat tomatoes deliciously? Let's cool them in the refrigerator.">

Customize title tag and description

The above settings can also be customized by editing "lib / Giblog / Command / build.pm".

If you know Perl, it will be easy to customize, but if you want to change the delimiter between the page title and the site title, simply rewrite it. only.

lib / Giblog / Command / build.pm

Changed the delimiter "-" between the page title and the site title to "|".

package Giblog::Command::build;

# omit

sub run {
  my ($self, @args) = @_;
  
  # omit
  
  for my $file (@$files) {
    
    #Parse title
    $api->parse_title_from_first_h_tag($data);

    #Edit title
    my $site_title = $config->{site_title};
    if ($data->{file} eq'index.html') {
      $data->{title} = $site_title;
    }
    else {
      #
      # Edited here
      #
      $data->{title} = "$data->{title} | $site_title";
    }

    #Add page link
    $api->add_page_link_to_first_h_tag($data, {root =>'index.html'});

    #Parse description
    $api->parse_description_from_first_p_tag($data);
  }
  
  # omit
}