问题描述:

I would like to use Jekyll to create a site. not a blog. Is there a way to avoid to have the creation date specified in the url and in the page's file name?

I think that the idea behind Jekyll is brilliant, but it seems too tied to blog generation content while it could be useful also in a more general use case.

网友答案:

In the _config file you can change the permalink to anything you like, for example mine is

permalink: /blog/:title

As for the date you can choose your own date using the YAML front matter, again in mine i have

title: example
date: you can pick what ever date you want
网友答案:

If you aren't producing blog pages, you can create files in the directory structure mapping to certain URLs. Running on localhost, if your directory has the structure

- _layouts/
- config.yml
- index.html
- some_other_page.html
- some_directory/
    - index.html
    - some_sub_page.html

You'll have content at the following locations after jekyll has processed the files:

  • 0.0.0.0:4000 (index.html)
  • 0.0.0.0:4000/some_other_page.html (some_other_page.html)
  • 0.0.0.0:4000/some_directory (some_directory/index.html)
  • 0.0.0.0:4000/some_directory/some_sub_page.html (some_directory/some_sub_page.html)

You can also use the permalink attribute on each post to set one manually, or set a different default in config.yml Permalinks only have a small subset of variables available to use and need to be defined in every single file you want to put in a non-standard location.

This directory structure will automatically categorize your posts too. So you can have:

- some_category (defined in the yaml front matter or the _config.yml
    - index.html
    - _posts/
        - some_post.md
        - some_other_post.md

And posts will automatically have the category 'some category', and index.html will appear at 0.0.0.0:4000/some-category, with the default permalink format. The category variable is available as :category in the permalink format string.

网友答案:

I came across this old question while looking for a way to organize jekyll pages in a _pages directory, similarly to _posts. then access this pages without displaying the whole path in the url.

The approach that worked better for me, is to use jekyll collections as follows:

1 - Add a pages collection in _config.yml :

collections:
   pages:
     output: true
     permalink: /:path/

2 - create a new directory named _pages (it should have the same collection name, prefixed by _)

3 - add the pages in the _pages folder, as .md or .html files starting with YAML Front Matter.

eg. /_pages/about.md will looks like:

---
layout: page
---

<!-- about page content -->

after building that, the URL of the about page will be <your-web-site>/about .

Alternatively, to display a collection name, you have to define its permalink as:

permalink: /:collection/:path/
相关阅读:
Top