Initial commit
This commit is contained in:
parent
5e1ca7f2f0
commit
f123acbd70
15
README.rst
Normal file
15
README.rst
Normal file
@ -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">'),
|
||||
)
|
1
__init__.py
Normal file
1
__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .replacer import *
|
23
replacer.py
Normal file
23
replacer.py
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user