In Pelican, how to create a page dedicated to hosting all the blog articles?
Asked Answered
P

5

20

In pelican, by default, blog articles are listed on the index.html file.

What I want instead is that I use a static page as my home page and put all the blog articles on a dedicated "Blog" page.

How can I get this done?

Pox answered 17/5, 2014 at 8:14 Comment(0)
C
18

While there are several possible methods for achieving your desired goals, I would start with the following changes to your settings file:

SITEURL = '/blog'
OUTPUT_PATH = 'output/blog'
PAGE_URL = '../{slug}.html'
PAGE_SAVE_AS = '../{slug}.html'
DISPLAY_PAGES_ON_MENU = False
DISPLAY_CATEGORIES_ON_MENU = False
MENUITEMS = [('Home', '/'), ('Blog', '/blog/')]

Put your blog posts in content/ as usual, and then create your home page with the following headers and save as content/pages/home.md:

Title: Home
URL: ../
Save_as: ../index.html

This is the home page.

Caveats:

  1. Dynamic navigation menu generation has been effectively turned off since it doesn't work well with this configuration. Highlighting for the currently-active menu item — a feature you normally get out-of-the-box — will not be present in this configuration and, if desired, must be implemented separately in your theme.

  2. If your theme's base.html template has a link to your site home that depends on SITEURL (e.g., as the notmyidea theme does), you will need to change the link to point to <a href="/"> instead.

Claudelle answered 18/5, 2014 at 16:49 Comment(3)
I just remade my website in this way. You can see the source here: github.com/drart/adamtindale.com Hopefully you find it helpful.Animus
I build this in my theme: if a DISPLAY_INDEX_ON_PAGES_MENU is True, it adds a menu entry which links to index.html or (if set) the INDEX_SAVE_AS page and highlights the menu item if one is on the blog index page (gist.github.com/jdittrich/3bcc2ce472720999e070)Pareu
For Pelican 4.2 this solution raises ERROR: Skipping ...content/pages/home.md: file '../index.html' would be written outside output pathIguanodon
P
7

Set the following in the pelicanconf

DIRECT_TEMPLATES = ['blog']
PAGINATED_DIRECT_TEMPLATES = ['blog']

1st line will set blog.html for the articles 2nd line will allow pagination of blog.html file

For the index page, create a pages folder in the content directory and create the .md file there and set save_as:index.html this will save the md file as index.html

Psychosis answered 18/5, 2014 at 7:20 Comment(0)
B
4

This is covered in the Pelican FAQ - "How can I override the generated URL of a specific page or article?"


Basically, in your contents folder, create two subfolders:

  • /contents/blogs, which will store all your blog entries
  • /content/pages, which will store your other static pages (including your home page)

In the pages subfolder, create a file (e.g. home.rst) with the option :save_as: index.html, which will make this file your home page. E.g.:

Home
####

:date: 2015-05-22 12:30
:url:
:save_as: index.html

This is my home page

In your pelicanconf.py file, specify the following options:

DISPLAY_PAGES_ON_MENU = False
DISPLAY_CATEGORIES_ON_MENU = True
USE_FOLDER_AS_CATEGORY = True 
PATH = 'content'
ARTICLE_PATHS = ['articles',]
PAGE_PATHS = ['pages',]
MENUITEMS = ()

You should now have a home page and a contents bar with a Blogs menu.

If you want to add more menus to the contents bar (for example an About or CV menu), create the corresponding files in your pages folder, and add them to MENUITEMS:

MENUITEMS = (
    ('About', '/pages/about.html'),
    ('CV', '/pages/cv.html'),
)
Beery answered 2/6, 2015 at 3:43 Comment(0)
R
2

I have an answer similar to the one Justin Mayer gave, except in mine I change blog article urls instead of page urls.

I've been getting the following error when trying to use the answer above, so it might be useful to other people having the same issue

ERROR: Skipping volunteering.rst: file '../volunteering.html' would be written outside output path
ERROR: Skipping presentations.rst: file '../presentations.html' would be written outside output path
  1. Make all article urls to be under 'blog/' url

    ARTICLE_URL = "blog/{date:%Y}-{date:%m}-{date:%d}-{slug}.html"
    ARTICLE_SAVE_AS = "blog/{date:%Y}-{date:%m}-{date:%d}-{slug}.html"
    
  2. Put blog index under 'blog/' url

    INDEX_SAVE_AS = "blog/index.html"
    
  3. Add a explicit menu item for blog index

    MENUITEMS = [
     ('home', '/'),
     ('blog', '/blog'),
    ]
    
  4. As your page is now an index page, automatically displaying link to that page in the menu will lead to a broken link, so you will have to set the following option and specify the following flag

    DISPLAY_PAGES_ON_MENU = False
    
  5. For the new index page, add a directive save_as, like Justin Mayer pointed it out. Here how it looks in rst

    About
    =====
    :slug: about
    :category: About
    :save_as: index.html
    

    This should give you a home page and an index page for articles.

  6. When you want to add more static pages, you will also need to add them in menu items that still contains '/pages' prefix in the url if you want links to the pages appear in a menu. i.e for the volunteering.rst with the following content,

    Volunteering
    ============
    :slug: about
    :category: About
    

Your MENUITEMS variable will look like the following

MENUITEMS = [
    ('home', '/'),
    ('blog', '/blog'),
    ('volunteering', '/pages/volunteering'),
]

I tested this answer on pelican 4.2.0.

Reactionary answered 28/12, 2019 at 4:4 Comment(2)
This solution is working, I confirm on Pelican 4.2. I had the same error using the older one.Iguanodon
I can confirm that this solution is working for me on Pelican 4.6 as well.Strepitous
I
0

You can use the following settings to put the index file for example at /blog/index.html.

INDEX_SAVE_AS = 'blog/index.html'
INDEX_URL = 'blog/'

Then you created a home.md page and use "save_as: index.html" directive for the actual home page.

Indeterminism answered 18/10, 2014 at 17:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.