Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add route for Hexo?

Tags:

hexo

In the theme _config.yml has two default route: / and /archieves. Is there possible to add a route like /about?

I tried to add /about in _config.yml, but Cannot GET /about/ shows.

like image 776
Leo Gao Avatar asked Mar 20 '15 12:03

Leo Gao


1 Answers

Three years passed, but maybe someone will find this useful.

If you want to actually add a route (without creating a page directory and/or files) you can use generator. Add this to a .js file inside your theme's scripts folder:

hexo.extend.generator.register("all-posts", function(locals) {
  return {
    path: "all-posts/index.html",
    data: locals,
    layout: ["all-posts", "index"]
  };
});

In this example, the page with layout 'all-posts' will be at /all-posts url.

This, of course, could be done by creating a folder with index.md file in it, with layout: all-posts in its front-matter

like image 54
Ilia Andrienko Avatar answered Oct 23 '22 13:10

Ilia Andrienko