-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e1ca7f
commit f123acb
Showing
3 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
`Replacer <https://github.com/narusemotoki/replacer>`_ | ||
====================================================== | ||
|
||
This is plugin of Pelican. You can replace a text of a generated HTML. You can write replacing rule in your pelicanconf.py. | ||
|
||
Example | ||
======= | ||
|
||
This example is replacing from '<table border="1" class="docutils">' to '<table class="table table-striped table-bordered table-hover">'. | ||
|
||
:: | ||
|
||
REPLACES = ( | ||
(u'<table border="1" class="docutils">', u'<table class="table table-striped table-bordered table-hover">'), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .replacer import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
import pelican | ||
|
||
|
||
def init(pelican_object): | ||
# I have no good idea. Pass settings to replace function. | ||
global replaces | ||
replaces = pelican_object.settings.get('REPLACES', ()) | ||
|
||
|
||
def replace(path, context): | ||
with open(path, 'r') as f: | ||
s = f.read() | ||
for src, tgt in replaces: | ||
s = s.decode('utf-8').replace(src.decode('utf-8'), tgt.decode('utf-8')) | ||
|
||
with open(path, 'w') as f: | ||
f.write(s.encode('utf-8')) | ||
|
||
|
||
def register(): | ||
pelican.signals.initialized.connect(init) | ||
pelican.signals.content_written.connect(replace) |