Repository: getnikola/nikola

Issue:
Customizable Read More and bigger leads
1. Not everybody is a fan of `<p><a href="">Read more...</a></p>`.  I believe this should be a configurable option, and it could even be set to nothing.
2. Another thing is the [lead](http://en.wikipedia.org/wiki/Lead_paragraph).  Some people (like me) use small, lead–style teasers for the posts.  Bootstrap has a nice `lead` class, which makes them bigger.  For an example of this at work, see [my blog homepage](http://kwpolska.tk) (showing only leads in a small size) and [a post](http://kwpolska.tk/blog/2013/02/08/nikola-the-best-blog-engine-ever/) — and take a look at the ugly [code behind it](https://github.com/Kwpolska/kwsblog/blob/master/lib/python2.7/site-packages/nikola/post.py#L196).  (and yes, I have to rewrite this every time you mess with `Post.text()`.)

"Read more" to the right...
I think that we need to change the "Read more" used in teasers to the right to get a better distribution of links...
Maybe is a very subjective idea, but, I think, it has to be configurable at least through templating, but the link is generated on the fly by post.py (https://github.com/ralsina/nikola/blob/e65ae90ee8392fcb5d724f3599a6c7ade5697a5b/nikola/post.py#L346), so it not configurable unless you hack the nikola code...

Ideas? Comments?



Discussion:
Well, I had to rewrite it because it was quite broken :-)

One change that may make your life easier is to move this into your theme:

```
            teaser_split = TEASER_REGEXP.split(data)
            data = '<div class="lead">{0}</div>{1}'.format(teaser_split[0],
                    teaser_split[3])
```

At least for Mako templates, there is no reason why that can't be done in the template. That way text() returns a reasonable thing, and you process it in the "presentation layer"

@Kwpolska want to discuss a possible plan to get this done in master? Otherwise we should close this.

For the first one:

> We should create config options: `INDEX_READ_MORE_LINK` and `RSS_READ_MORE_LINK` and in post.text(), replace this:
> 
> ``` python
>                 teaser_str = self.messages[lang]["Read more"] + '...'
>                 teaser += '<p><a href="{0}">{1}</a></p>'.format(
>                     self.permalink(lang), teaser_str)
> ```
> 
> with this:
> 
> ``` python
>                 teaser += kw['*_read_more_link'].format(link=link, read_more=self.messages[lang]["Read more"])
> ```
> 
> Next, add the following to `Nikola.config`:
> 
> ``` python
> {'INDEX_READ_MORE_LINK': '<p><a href="{link}>{read_more}…</a></p>',
>  'RSS_READ_MORE_LINK': '<p><a href="{link}>{read_more}…</a></p>'}
> ```
> 
> I also think that we should move the ellipsis to the locale files, and make it a nice UTF-8 one (`…` vs `...`, … vs ...)

For the second one, just steal the code from [my blog](https://github.com/Kwpolska/kwsblog/blob/master/themes/kw/templates/story.tmpl#L10) if you want it for yourself, and add an option or something if you want it to include it for everyone.

(note: I don’t have time to do it right now.)

~~It's ok, I can do it (probably today) Thanks!~~

I'd rather not do two options because I don't want Post.text to have to know if it's being asked about a RSS text or a webpage text.

Ugh, and there's an additiona problem in that posts are not configuration-aware, so this option would have to be passed every time someone calls Post.text() or injected into each post on creation, and both things are ugly, and making things regenerate when you change this option is a mess.

I will punt this to some indeterminate future, sorry :-(

The "Read more" is now customizable from the teaser marker:

.. TEASER_END: this will appear instead of read more...

My first idea is to make `'<p><a href="{0}">{1}</a></p>'` part of the template or something like that...

On 23/07/13 14:22, Damián Avila wrote:

> My first idea is to make |'<p><a href="{0}">{1}</a></p>'| part of the
> template or something like that...

But that is not always there... how about making it a span with a class
so it can be styled by the theme?
In general, nikola is producing HTML that is not labeled enough.

#412 perchance?

In general, should we add some default classes to HTML elements in the template ?

On 30/07/13 12:05, Dhruv Baldawa wrote:

> In general, should we add some default classes to HTML elements in the
> template ?

I think that's a good idea, and it will make styling via pure CSS much
easier.


Resolving patch:
diff --git a/nikola/nikola.py b/nikola/nikola.py
--- a/nikola/nikola.py
+++ b/nikola/nikola.py
@@ -153,6 +153,7 @@ def __init__(self, **config):
                 ("stories/*.txt", "stories", "story.tmpl", False),
             ),
             'PRETTY_URLS': False,
+            'READ_MORE_LINK': '<p class="more"><a href="{link}">{read_more}…</a></p>',
             'REDIRECTIONS': [],
             'RSS_LINK': None,
             'RSS_PATH': '',
diff --git a/nikola/plugins/task_render_posts.py b/nikola/plugins/task_render_posts.py
--- a/nikola/plugins/task_render_posts.py
+++ b/nikola/plugins/task_render_posts.py
@@ -27,6 +27,7 @@
 from copy import copy
 import codecs
 import string
+import nikola.post
 
 from nikola.plugin_categories import Task
 from nikola import utils, rc4
@@ -56,6 +57,8 @@ def gen_tasks(self):
             "hide_untranslated_posts": self.site.config['HIDE_UNTRANSLATED_POSTS'],
         }
 
+        nikola.post.READ_MORE_LINK = self.site.config['READ_MORE_LINK']
+
         flag = False
         for lang in kw["translations"]:
             deps_dict = copy(kw)
diff --git a/nikola/post.py b/nikola/post.py
--- a/nikola/post.py
+++ b/nikola/post.py
@@ -39,7 +39,7 @@
 __all__ = ['Post']
 
 TEASER_REGEXP = re.compile('<!--\s*TEASER_END(:(.+))?\s*-->', re.IGNORECASE)
-
+READ_MORE_LINK = '<p class="more"><a href="{link}">{read_more}…</a></p>'
 
 class Post(object):
 
@@ -342,10 +342,13 @@ def text(self, lang=None, teaser_only=False, strip_html=False):
         if teaser_only:
             teaser = TEASER_REGEXP.split(data)[0]
             if teaser != data:
-                teaser_str = TEASER_REGEXP.search(data).groups()[-1] or \
-                    self.messages[lang]["Read more"] + '...'
-                teaser += '<p><a href="{0}">{1}</a></p>'.format(
-                    self.permalink(lang), teaser_str)
+                if TEASER_REGEXP.search(data).groups()[-1]:
+                    teaser += '<p class="more"><a href="{0}">{1}</a></p>'.format(
+                        self.permalink(lang), TEASER_REGEXP.search(data).groups()[-1])
+                else:
+                    teaser += READ_MORE_LINK.format(
+                        link=self.permalink(lang),
+                        read_more=self.messages[lang]["Read more"])
                 # This closes all open tags and sanitizes the broken HTML
                 document = lxml.html.fromstring(teaser)
                 data = lxml.html.tostring(document, encoding='unicode')


Test patch: