Skip to content

Commit

Permalink
Fix #1222 -- split READ_MORE_LINK into RSS_ and INDEX_ versions
Browse files Browse the repository at this point in the history
Signed-off-by: Chris “Kwpolska” Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Apr 13, 2014
1 parent 1c9a199 commit 8375c23
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,8 @@ New in master
Features
--------

* Replaced ``READ_MORE_LINK`` with ``INDEX_READ_MORE_LINK`` and
``RSS_READ_MORE_LINK`` (Issue #1222)
* Added reading_time, remaining_reading_time, paragraph_count,
remaining_paragraph_count tags for READ_MORE_LINK (Issue #1220)
* Add canonical link in listings.
Expand Down
8 changes: 6 additions & 2 deletions nikola/conf.py.in
Expand Up @@ -339,7 +339,7 @@ THEME = ${THEME}
# Show only teasers in the index pages? Defaults to False.
# INDEX_TEASERS = False

# A HTML fragment with the Read more... link. (translatable)
# HTML fragments with the Read more... link.
# The following tags exist and are replaced for you:
# {link} A link to the full post page.
# {read_more} The string “Read more” in the current language.
Expand All @@ -349,7 +349,11 @@ THEME = ${THEME}
# {remaining_paragraph_count} The amount of paragraphs in the post, sans the teaser.
# {{ A literal { (U+007B LEFT CURLY BRACKET)
# }} A literal } (U+007D RIGHT CURLY BRACKET)
READ_MORE_LINK = ${READ_MORE_LINK}

# 'Read more...' for the index page, if INDEX_TEASERS is True (translatable)
INDEX_READ_MORE_LINK = ${READ_MORE_LINK}
# 'Read more...' for the RSS_FEED, if RSS_TEASERS is True (translatable)
RSS_READ_MORE_LINK = ${READ_MORE_LINK}

# A HTML fragment describing the license, for the sidebar.
# (translatable)
Expand Down
19 changes: 17 additions & 2 deletions nikola/nikola.py
Expand Up @@ -285,7 +285,8 @@ def __init__(self, **config):
'PAGES': (("stories/*.txt", "stories", "story.tmpl"),),
'PRETTY_URLS': False,
'FUTURE_IS_NOW': False,
'READ_MORE_LINK': DEFAULT_READ_MORE_LINK,
'INDEX_READ_MORE_LINK': DEFAULT_READ_MORE_LINK,
'RSS_READ_MORE_LINK': DEFAULT_READ_MORE_LINK,
'REDIRECTIONS': [],
'RSS_LINK': None,
'RSS_PATH': '',
Expand Down Expand Up @@ -416,6 +417,20 @@ def __init__(self, **config):
utils.LOGGER.warn('HIDE_UNTRANSLATED_POSTS conflicts with SHOW_UNTRANSLATED_POSTS, ignoring HIDE_UNTRANSLATED_POSTS.')
self.config['SHOW_UNTRANSLATED_POSTS'] = not config['HIDE_UNTRANSLATED_POSTS']

# READ_MORE_LINK has been split into INDEX_READ_MORE_LINK and RSS_READ_MORE_LINK
# TODO: remove on v8
if 'READ_MORE_LINK' in config:
utils.LOGGER.warn('The READ_MORE_LINK option is deprecated, use INDEX_READ_MORE_LINK and READ_MORE_LINK instead.')
if 'INDEX_READ_MORE_LINK' in config:
utils.LOGGER.warn('READ_MORE_LINK conflicts with INDEX_READ_MORE_LINK, ignoring READ_MORE_LINK.')
else:
self.config['INDEX_READ_MORE_LINK'] = config['READ_MORE_LINK']

if 'RSS_READ_MORE_LINK' in config:
utils.LOGGER.warn('READ_MORE_LINK conflicts with RSS_READ_MORE_LINK, ignoring READ_MORE_LINK.')
else:
self.config['RSS_READ_MORE_LINK'] = config['READ_MORE_LINK']

# Moot.it renamed themselves to muut.io
# TODO: remove on v8?
if self.config.get('COMMENT_SYSTEM') == 'moot':
Expand Down Expand Up @@ -850,7 +865,7 @@ def generic_rss_renderer(self, lang, title, link, description, timeline, output_
for post in timeline[:feed_length]:
old_url_type = self.config['URL_TYPE']
self.config['URL_TYPE'] = 'absolute'
data = post.text(lang, teaser_only=rss_teasers, strip_html=rss_plain)
data = post.text(lang, teaser_only=rss_teasers, strip_html=rss_plain, rss_read_more_link=True)
if feed_url is not None and data:
# Massage the post's HTML (unless plain)
if not rss_plain:
Expand Down
2 changes: 1 addition & 1 deletion nikola/plugins/task/indexes.py
Expand Up @@ -58,7 +58,7 @@ def gen_tasks(self):
"indexes_pages": self.site.config['INDEXES_PAGES'],
"indexes_pages_main": self.site.config['INDEXES_PAGES_MAIN'],
"blog_title": self.site.config["BLOG_TITLE"],
"read_more_link": self.site.config["READ_MORE_LINK"],
"rss_read_more_link": self.site.config["RSS_READ_MORE_LINK"],
}

template_name = "index.tmpl"
Expand Down
2 changes: 1 addition & 1 deletion nikola/plugins/task/rss.py
Expand Up @@ -58,7 +58,7 @@ def gen_tasks(self):
"show_untranslated_posts": self.site.config['SHOW_UNTRANSLATED_POSTS'],
"feed_length": self.site.config['FEED_LENGTH'],
"tzinfo": self.site.tzinfo,
"read_more_link": self.site.config["READ_MORE_LINK"],
"rss_read_more_link": self.site.config["RSS_READ_MORE_LINK"],
}
self.site.scan_posts()
# Check for any changes in the state of use_in_feeds for any post.
Expand Down
6 changes: 4 additions & 2 deletions nikola/post.py
Expand Up @@ -401,12 +401,13 @@ def _translated_file_path(self, lang):
else:
return get_translation_candidate(self.config, self.base_path, sorted(self.translated_to)[0])

def text(self, lang=None, teaser_only=False, strip_html=False, show_read_more_link=True):
def text(self, lang=None, teaser_only=False, strip_html=False, show_read_more_link=True, rss_read_more_link=True):
"""Read the post file for that language and return its contents.
teaser_only=True breaks at the teaser marker and returns only the teaser.
strip_html=True removes HTML tags
show_read_more_link=False does not add the Read more... link
rss_read_more_link=True uses RSS_READ_MORE_LINK instead of INDEX_READ_MORE_LINK
lang=None uses the last used to set locale
All links in the returned HTML will be relative.
Expand Down Expand Up @@ -452,7 +453,8 @@ def text(self, lang=None, teaser_only=False, strip_html=False, show_read_more_li
self.permalink(lang),
TEASER_REGEXP.search(data).groups()[-1])
else:
teaser += self.config['READ_MORE_LINK'](lang).format(
l = self.config['RSS_READ_MORE_LINK'](lang) if rss_read_more_link else self.config['INDEX_READ_MORE_LINK'](lang)
teaser += l.format(
link=self.permalink(lang),
read_more=self.messages[lang]["Read more"],
reading_time=self.reading_time,
Expand Down

0 comments on commit 8375c23

Please sign in to comment.