LouisBarranqueiro / hexo-theme-tranquilpeak

:lipstick: A gorgeous responsive theme for Hexo blog framework
https://louisbarranqueiro.github.io/hexo-theme-tranquilpeak/
GNU General Public License v3.0
1.86k stars 484 forks source link

Increasing excerpt character count #89

Closed MattieTK closed 9 years ago

MattieTK commented 9 years ago

Hi Louis,

Thanks for this great theme.

I was wondering if you could give any hints on where you've located the script that shortens posts to 300 characters as I can't find it anywhere. If it's part of core and you could tell me whereabouts it is that would be very helpful also.

Alternatively if you could make if configurable in a future release that would be great, as I suspect others would like to display their full posts/more/less on the page.

In this case might I suggest something like excerptLength in _config.yaml. -1 (or another char) for full post 0 for zero-length excerpt and 1 onwards for the number of characters

Thanks for your help

chawyehsu commented 9 years ago

It's in /layout/_partial/index.ejs#L44.

MattieTK commented 9 years ago

@h404bi Thanks very much!

Remains as to whether @LouisBarranqueiro would think to make this configurable. Might do a PR if that's the case.

Thanks again

LouisBarranqueiro commented 9 years ago

Yeah it can be configurable in configuration file but it's better to use <!-- more --> comment. Why do you want this feature?

chawyehsu commented 9 years ago

+1. <!-- more --> is enough.

MattieTK commented 9 years ago

Thanks for opening a discussion on this Louis.

I've found that <!-- more --> to not be working on my installation for some reason. For example, any post above 200 characters, when I place <!-- more --> either within the first 200 or outside of them, nothing changes. This may be because I have https://github.com/lalunamel/hexo-front-matter-excerpt installed though as I believe that overrides it.

Unfortunately for users like me there's no way without copying the entire post into the excerpt field of effectively having no click-through prompt and the whole post on the index page. I sense this is the same for those with the <!-- more --> tag, unless they paste <!-- more --> after their copy, which I'm not sure if that results in a confusing link or not.

Anyway, I've made a slight alteration to /layout/_partial/index.ejs#L44 to add another option to posts I have called fullPost.

Effectively this is now the content of my postShorten-excerpt div.

<% if (post.excerpt) { %>
                        <%- post.excerpt %>
                    <% } if (post.fullpost) { %>
                        <p>
                            <%- post.content %><br>
                    <% } else { %>
                        <p>
                            <%- post.content.replace(/<(?:.|\n)*?>/gm, '').substr(0, 200) %><br>
                    <% } %>
                    <% if ((post.link) && __('post.go_to_website')) { %>
                            <a href="<%- url_for(post.link) %>" target="new" class="postShorten-excerpt_link link"><%= __('post.go_to_website')  %> </a>
                    <% } else { %>
                        <% if (__('post.read_more') && (post.fullpost != true)) { %>
                            <a href="<%- url_for(post.path) %>" class="postShorten-excerpt_link link "><%- __('post.read_more') %></a>
                            <% if (post.readingtime) { %>
                                <span class="postShorten-readingtime"><%= ' - ' + post.readingtime + ' min read' %></span>
                            <% } %>
                        <% } %>
                    <% } %>
                    <% if (!post.excerpt) { %>
                        </p>
                    <% } %>

Not sure if this is of interest adding to the core of the theme but I think it effectively solves what is more of a workaround in adding <!-- more --> to the end of every post you want to interact this way.

LouisBarranqueiro commented 9 years ago

So let's add the excerpt variable in front matter in Tranquilpeak theme and control perfectly the behavior on index page :) What do you think about that?

kaedea commented 9 years ago

How about extract the default count as a variable int the theme's _config.yml?

LouisBarranqueiro commented 9 years ago

Yes, we can also do that. But I implement this feature, in case of user forget to add the <!-- more --> comment and keep the right style on index page.

kaedea commented 9 years ago

I woudl like to mention that 200 Chinese or Japanese Characters will take much more space than English letter. So it should be a smller value for Chinese or Japanese user. enter image description here

LouisBarranqueiro commented 9 years ago

Yes lol. But What we do?

  1. implement new feature : excerpt variable that overwrite <!-- more --> comment and remove characters count feature
  2. Only use ` comment and remove characters count feature

I prefer 1.

kaedea commented 9 years ago

prefer 1

chawyehsu commented 9 years ago

I prefer using <!-- more --> tag. Cuz it's control is better, especially for CJK.

LouisBarranqueiro commented 9 years ago

yes <!-- more --> is useful and very easy to use but the excerpt variable can be interesting when you want to write a special content only displayed in index page to introduce your article and not displayed in the content.

chawyehsu commented 9 years ago

So the excerpt variable means special excerpt content?

excerpt: "Wow, now I can customize my excerpt!"

That's useful. But this feature might not conform to @MattieTK 's idea, he wants excerpt length controllable.

LouisBarranqueiro commented 9 years ago

yes. yes, but customize the excerpt is better and easy to use than control number of letter displayed for all posts :p What do you think @MattieTK ?

chawyehsu commented 9 years ago

hah, I like it, vote 1. xD

kaedea commented 9 years ago

The thumbnail image looks well with auto-excerpt of all posts, but the length of excerpt needs to be configurable. Which one is better? To put this variable in the theme's conf, or in the post so that each post can control it itself. If you do not use auto-excerpt, the index page may looks ugly if the shorten posts' height differ so much.

LouisBarranqueiro commented 9 years ago

as I said customize the excerpt is better and easy to use than control number of letter displayed

MattieTK commented 9 years ago

Sorry @LouisBarranqueiro I've not managed to get back to you. Thanks to @h404bi and @kaedea for discussing.

I agree with you that I think controlling the excerpt is better than controlling character count, and I'm sorry that this is what the thread began with when I think the discussion has moved past it.

As I said above I think there are three/four possible situations you have to account for: 1) User is happy with 200 character count excerpt automatically chosen 2) User wants to control excerpt either past 200 characters OR 2a) User wants to control excerpt specifically, to the verge of having different text 3) User wants to include entire post (technically a subset of 2 or 2a, but is worth considering as a separate option).

Now let's see what we can currently do.

1) Doesn't require any changes, it's just supported by default 2) Is supported by the <!-- more --> tag in tagging it where they want the excerpt to end (though this is more work), or by a custom excerpt variable 2a) Is not supported by the <!-- more --> tag but is supported by a custom excerpt variable 3) Is not supported by the tag but is supported by the custom excerpt variable (though this is more work, you have to effectively have your post written twice into the body and the excerpt variable.) Better supported by a new post-wide tag like fullPost above.

I think a combination of a displayFullPost variable that is true or false, in order to skip an excerpt entirely, and a custom excerpt variable is a happy mix. This is what I've put on my hex.io instance as I've shown above in my code.

Given that it's all static site generation I can't really see the performance hit if we add more options over fewer options either.

LouisBarranqueiro commented 9 years ago

I'm going to implement 2a and also an other feature to display all content of all posts on index page

MattieTK commented 9 years ago

That's great Louis, thanks for being so attentive

ghost commented 9 years ago

That plugin seems to have bug

LouisBarranqueiro commented 9 years ago

what are you talking about @Imyssed ?

ghost commented 9 years ago

https://github.com/lalunamel/hexo-front-matter-excerpt (This plugin)

LouisBarranqueiro commented 9 years ago

yeah but which bug? But i didn't use this plugin, I created an other one for Tranquilpeak

ghost commented 9 years ago

It cause cash on my computer... Comments to the MattieTK ;) Don't worry

LouisBarranqueiro commented 9 years ago

feature 3 implemented. post content and its gallery image can now be displayed on index page if there is no <!-- more --> and <!-- exceprt --> comment in post content

I will release the new version this WE (sunday I think)