3

I have setup a hexo blog and configure two top level domain pointing to same instance e.g. domain.com and domain.org

I want to set canonical URL for the entire site. There is plugin for this but I'm not able to understand what to do as I don't know jade or ejs.

Is there any way I can do this with or without modifying the themes?

pr4bh4sh
  • 654
  • 3
  • 12
  • 19

1 Answers1

2

No, there is no way to this without modifying the theme (or with a theme that already support it).

Theme is a kind of template for your pages, during site generation the theme is processed and your content is inserted, the result is saved is a .html file. It is easy to customize a theme for just include canonical link.

Since I don´t know what theme are you using, I will pick the tranquilpeak as example. In the theme source find out layout/_partial/head.ejs, this file is responsible for generate the <head> section of every HTML file in your blog. In this file, after <head> tag you will put the plugin helper <%- autoCanonical(config, page) %>.

EJS here, is a template language. What is put inside tag <% %> will be processed during site generation and its result will be put into final HTML file. The plugin you mentioned has a helper function called autoCanonical that will be evaluated by Hexo´s EJS pre processor and whatever it returns will go to the HTML.

EDIT:

Using theme https://github.com/tufu9441/maupassant-hexo (Jade templates)

This theme it is based on Jade templates, you shall add the plugin helper somewhere around Line 26 of base.jade file and also a similar modification to this place on base-without-sidebar.jade file

| !{ autoCanonical(config, page) }

will do the trick.

JrBenito
  • 973
  • 8
  • 30
  • Found the place, notice that layout directory on theme project has all the layouts for your hexo blog. For instance, a post uses post layout is held on post.jade. Its content is expanded inside "block content" of the base,jade layout. So base.jade has the basic html scaffold and other layouts are used to fill the gaps (footers, headers, sidebars, etc). – JrBenito Oct 19 '16 at 20:53