Skip to content

Commit

Permalink
Add the option to configure TEASER_REGEXP
Browse files Browse the repository at this point in the history
  • Loading branch information
yamila-moreno committed Aug 15, 2015
1 parent 950afc8 commit fad190e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
* `Tolu Sonaike <https://github.com/tolusonaike>`_
* `Troy Toman <https://github.com/troytoman>`_
* `Udo Spallek <https://github.com/udono>`_
* `Yamila Moreno <https://github.com/yamila-moreno>`_
* `Yaşar Arabacı <https://github.com/yasar11732>`_
* `Yasuhiko Shiga <https://github.com/quoth>`_
* `Zhaojun Meng <https://github.com/zhaojunmeng>`_
Expand Down
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
New in Master
=============

Features
--------

* New option to use custom, and several TEASER_ENDs

Bugfixes
--------

Expand Down
9 changes: 8 additions & 1 deletion docs/manual.txt
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ to your configuration:
However, starting with Nikola v7, you can now use ``.meta`` files and put
all metadata you want, complete with the explanations — they look just like
the beginning of our reST files.

.. code:: restructuredtext

.. title: How to make money
Expand Down Expand Up @@ -497,6 +497,13 @@ change that text, you can use a custom teaser:

.. TEASER_END: click to read the rest of the article

You can override the default value for `TEASER_END` in `conf.py`:

..code:: python

import re
TEASER_REGEXP = re.compile('<!--\s*(more|TEASER_END)(:(.+))?\s*-->', re.IGNORECASE)

Or you can completely customize the link using the ``READ_MORE_LINK`` option

.. code:: python
Expand Down
7 changes: 4 additions & 3 deletions nikola/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,12 @@ def text(self, lang=None, teaser_only=False, strip_html=False, show_read_more_li
data = lxml.html.tostring(document, encoding='unicode')

if teaser_only:
teaser = TEASER_REGEXP.split(data)[0]
teaser_regexp = self.config.get('TEASER_REGEXP', TEASER_REGEXP)
teaser = teaser_regexp.split(data)[0]
if teaser != data:
if not strip_html and show_read_more_link:
if TEASER_REGEXP.search(data).groups()[-1]:
teaser_text = TEASER_REGEXP.search(data).groups()[-1]
if teaser_regexp.search(data).groups()[-1]:
teaser_text = teaser_regexp.search(data).groups()[-1]
else:
teaser_text = self.messages[lang]["Read more"]
l = self.config['RSS_READ_MORE_LINK'](lang) if rss_read_more_link else self.config['INDEX_READ_MORE_LINK'](lang)
Expand Down

0 comments on commit fad190e

Please sign in to comment.