Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace 'PAGES' with 'pages' across all themes #497

Merged
merged 1 commit into from Apr 8, 2017

Conversation

adamatan
Copy link
Contributor

@adamatan adamatan commented Mar 7, 2017

The problem

Pelican now uses pages instead of PAGES in the HTML Jinja templates. However, not all themes have updated the code in their HTML files, which caused this common problem -

Since I upgraded Pelican my pages are no longer rendered

Which was reported as issue #437.

My solution

Regex substitution across all themes.

Code

I've used the following Python code to replace the occurrences in all HTML files. It's not intended to be efficient or beautiful, but please let me know if you spot any bugs or shortcomings.

#!/usr/bin/python

import os
import re

regex = '(.*%.*)([^A-Za-z_])(PAGES)([^A-Za-z_])(.*%.*)'
repl = '\g<1>\g<2>pages\g<4>\g<5>'

i = 0
for cur_dir, sub_dirs, filenames in os.walk('.'):
    html_filenames = [filename for filename in filenames if re.match('.*html$', filename)]
    if html_filenames:
        for filename in html_filenames:
            path = cur_dir + os.sep + filename
            with open(path) as rf:
                content = rf.read()

            matches = re.findall(regex, content)
            if matches:
                print(path)
                for match in matches:
                    i += 1
                    print("\t {:3d}  {}".format(i, ''.join(match).strip()))
                with open(path, 'wt') as wf:
                    wf.write(re.sub(regex, repl, content))

@adamatan adamatan changed the title Replace 'PAGES' with 'pages' across all themes Replace PAGES with pages across all themes Mar 7, 2017
@adamatan adamatan changed the title Replace PAGES with pages across all themes Replace 'PAGES' with 'pages' across all themes Mar 7, 2017
@almet
Copy link
Member

almet commented Apr 8, 2017

Hi, thanks for taking the time to open an issue and for pinging us on twitter.

The changes looks fine to me, so let's merge these!

Please, note that the best way to reach the development team is via IRC, as outlined in the README of the project. I'm taking the liberty to merge here but I'm actually not the maintainer of pelican anymore.

@almet almet merged commit 7c80c7f into getpelican:master Apr 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants