Closed MattieTK closed 9 years ago
It's in /layout/_partial/index.ejs#L44.
@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
Yeah it can be configurable in configuration file but it's better to use <!-- more -->
comment. Why do you want this feature?
+1. <!-- more -->
is enough.
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.
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?
How about extract the default count as a variable int the theme's _config.yml
?
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.
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.
Yes lol. But What we do?
excerpt
variable that overwrite <!-- more -->
comment and remove characters count featureI prefer 1.
prefer 1
I prefer using <!-- more -->
tag. Cuz it's control is better, especially for CJK.
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.
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.
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 ?
hah, I like it, vote 1. xD
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.
as I said customize the excerpt is better and easy to use than control number of letter displayed
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.
I'm going to implement 2a and also an other feature to display all content of all posts on index page
That's great Louis, thanks for being so attentive
That plugin seems to have bug
what are you talking about @Imyssed ?
https://github.com/lalunamel/hexo-front-matter-excerpt (This plugin)
yeah but which bug? But i didn't use this plugin, I created an other one for Tranquilpeak
It cause cash on my computer... Comments to the MattieTK ;) Don't worry
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)
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 post0
for zero-length excerpt and1
onwards for the number of charactersThanks for your help