GithubHelp home page GithubHelp logo

isabella232 / pelican-page-hierarchy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from transifex/pelican-page-hierarchy

0.0 0.0 0.0 88 KB

A Pelican plugin that creates a URL hierarchy for pages that matches the filesystem hierarchy of their sources.

Python 100.00%

pelican-page-hierarchy's Introduction

Page Hierarchy

Author: Ahmad Khayyat ([email protected])

A Pelican plugin that creates a URL hierarchy for pages that matches the filesystem hierarchy of their sources.

For example, to have the following filesystem structure of page sources result in the URLs listed next to each file,

└── content/pages/           #   PAGE_DIR
    ├── about.md             # URL: pages/about/
    ├── projects.md          # URL: pages/projects/
    ├── projects/            #   (directory)
    │   ├── p1.md            # URL: pages/projects/p1/
    │   ├── p2.md            # URL: pages/projects/p2/
    │   └── p2/              #   (directory)
    │       └── features.md  # URL: pages/projects/p2/features/
    └── contact.md           # URL: pages/contact/

you can use this plugin with the following Pelican settings:

# pelicanconf.py
PAGE_URL = '{slug}/'
PAGE_SAVE_AS = '{slug}/index.html'
SLUGIFY_SOURCE = 'basename'

When generating the url and save_as attributes, the plugin prefixes the page's slug by its relative path. Although the initial slug is generated from the page's title by default, it can be generated from the source file basename by setting the SLUGIFY_SOURCE setting to 'basename', as shown in the settings snippet above. The slug can also be set using PATH_METADATA.

This plugin is compatible with Pelican translations.

Parent and Children Pages

This plugin also adds three attributes to each page object:

  • parent: the immediate parent page. None if the page is top-level. If a translated page has no parent, the default-language parent is used.

  • parents: a list of all ancestor pages, starting from the top-level ancestor.

  • children: a list of all immediate child pages, in no specific order.

These attributes can be used to generate breadcrumbs or nested navigation menus. For example, this is a template excerpt for breadcrumbs:

<ul class="breadcrumb">
  <li><a href="{{ SITEURL }}/" title="{{ SITENAME }}">
    <i class="fa fa-home fa-lg"></i>
  </a></li>
  {% for parent in page.parents %}
  <li><a href="{{ SITEURL }}/{{ parent.url }}">{{ parent.title }}</a></li>
  {% endfor %}
  <li class="active">{{ page.title }}</li>
</ul>

pelican-page-hierarchy's People

Contributors

akhayyat avatar kernc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.