Closed jbcpollak closed 9 years ago
On a related note, and related to #89, is there any way to disable excerpting? I would like to force some posts to be included in their entirety on the index page.
Just add some code by yourself~ Add these in index.ejs#L39
<div class="postShorten-excerpt" itemprop="articleBody">
<% if (post.excerpt) { %>
<%- post.excerpt %>
<% } else { %>
<% if (post.full) { %> // Add this line
<%- post.content %> // Add this line
<% } else { %> // Add this line
<p>
<%- post.content.replace(/<(?:.|\n)*?>/gm, '').substr(0, 200) %><br>
<% } %>
Not test.Hope it works :P
You are in a case that I hadn't anticipate. You are not using <!-- more -->
, and the theme automatically cut the post content but the output isn't rendered! I will fix that.
Thank you!
On Fri, Oct 2, 2015, 8:08 AM Louis Barranqueiro notifications@github.com wrote:
You are in a case that I hadn't anticipate. You are not using , and the theme automatically cut the post content but the output isn't rendered! I will fix that.
— Reply to this email directly or view it on GitHub https://github.com/LouisBarranqueiro/tranquilpeak-hexo-theme/issues/108#issuecomment-144999585 .
I also noticed that for many posts the automatically truncated output was cut off mid word. I don't know if that is related or something you can fix, but I was expecting truncation at the end of a word with ellipsis at the end.
On Fri, Oct 2, 2015, 9:58 AM Joshua Chaitin-Pollak josh@offthehill.org wrote:
Thank you!
On Fri, Oct 2, 2015, 8:08 AM Louis Barranqueiro notifications@github.com wrote:
You are in a case that I hadn't anticipate. You are not using , and the theme automatically cut the post content but the output isn't rendered! I will fix that.
— Reply to this email directly or view it on GitHub https://github.com/LouisBarranqueiro/tranquilpeak-hexo-theme/issues/108#issuecomment-144999585 .
Yeah, it can be an idea, but I recommend to use <!-- more -->
tag and soon the excerpt
front matter variable.
OK that makes sense. With the fix you mentioned, what would be the changed behavior?
On Fri, Oct 2, 2015, 1:49 PM Louis Barranqueiro notifications@github.com wrote:
Yeah, it can be an idea, but I recommend to use tag and soon the excerpt front matter variable.
— Reply to this email directly or view it on GitHub https://github.com/LouisBarranqueiro/tranquilpeak-hexo-theme/issues/108#issuecomment-145098633 .
Like the commit said :p tranquilpeak will render (markdown engine) the automatic post exceprt
@LouisBarranqueiro - sorry, I wasn't following the thread in my email and I didn't realize a commit had been made (I didn't get an email about it!) - I'll check it out now!
np :D
With your commit I get this result:
The GT1 Championship this weekend was a pretty soggy affair, but I got to take some photos…
<a href=”http://www.joshpollak.com/Cars/Racing/2011-FIA-GT1-Beijing/18995038_thTJxj#1475626489_JS8
When you truncate before rendering the markdown, I guess you can end up with invalid code which can't be rendered.
I tried changing the code to be the following, and it works a bit better:
<% if (post.excerpt) { %>
<%- post.excerpt %>
<% } else { %>
<p>
<%- function(s) {
var maxLen = 200;
var content = markdown(s);
var toLong = content.length>maxLen;
var s_ = toLong ? content.substr(0,maxLen-1) : content;
return s_.substr(0,s_.lastIndexOf(' ')) + " …";
}(post.content)
%><br>
<% } %>
This truncates the code (on a word boundary) after rendering to markdown. The plus side is this doesn't look too bad, the downside is you are truncating including counting the HTML, so anchor tags, etc, get counted in your word count.
So a post like this:
I have previously posted about using MacFuse with Snow Leopard, but if you have already upgraded to OS X Lion, you may be having trouble finding a version of FUSE to use.
Gets rendered as:
I have previously posted about ...
The post about the car image above works ok, but the image doesn't appear.
Then I tried this small change:
<% if (post.excerpt) { %>
<%- post.excerpt %>
<% } else { %>
<p>
<%- function(s) {
var maxLen = 200;
var content = s;
var toLong = content.length>maxLen;
var s_ = toLong ? content.substr(0,maxLen-1) : content;
return markdown(s_.substr(0,s_.lastIndexOf(' ')) + " …");
}(post.content)
%><br>
<% } %>
This gives the same result with the MacFuse post, but truncates the race car post in the middle of the anchor tag:
The GT1 Championship this weekend was a pretty soggy affair, but I got to take some photos…
<a …
What I think I would really like is the ability to disable excerpting completely for certain posts. It seems like automated 200-character truncation can't be done cleanly pre or post markdown rendering so using <!-- more -->
or the 'excerpt' front-matter makes a lot of sense, but what about when you don't want an excerpt at all?
I could use <!-- more -->
at the bottom of the post, but if there is nothing more to add, I really don't want to have a 'continue reading' link.
Yeah, clearly, It seems to be the better solution. If excerpt
variable isn't defined in front-matter and <!-- more -->
doesn't exist in post content so post content will be displayed.
Yeah, I think manually setting the excerpt is the only safe way to go. Is post.excerpt
set by hexo or tranquilpeak? I couldn't find where it was being determined.
But I'am not clearly convicted in terms of UX & UI. What is your problem currently? You just wanna display some images and link in post excerpt but not the all content?
No, the problem its its a short post, but longer than 200 characters, or with an image. See here:
http://code.joshpollak.com/blog/
Compare the FIA GT1 post on that page to how it looks on its own page:
http://code.joshpollak.com/2011/09/12/fia-gt1-championship-in-beijing/
And how these longer posts get truncated on the main page:
http://code.joshpollak.com/2011/07/21/macfuse-for-os-x-lion/ http://code.joshpollak.com/2011/06/03/java-static-variables-are-wrong-almost-always/
I really like the look of tranquilpeak with the short excerpts on the main page, but when migrating a blog or writing long posts, the hard-truncation seems to cause a lot of problems.
Check the new feature :) I will release the new version this sunday
I reviewed the code, but I don't think I get it. :/
?
I just released the new version 1.4.0, read user doc - define post excerpt and display all post excerpt content sections
You should be able to do what you want now. Re-open the issue, if you encounter some problem
Looks great, I'll try it out!
On Mon, Oct 12, 2015 at 9:11 AM Louis Barranqueiro notifications@github.com wrote:
I just released the new version 1.4.0 https://github.com/LouisBarranqueiro/tranquilpeak-hexo-theme/releases/tag/v1.4.0, read user doc - define post excerpt https://github.com/LouisBarranqueiro/tranquilpeak-hexo-theme/blob/master/docs/user.md#define-post-excerpt and display all post excerpt content https://github.com/LouisBarranqueiro/tranquilpeak-hexo-theme/blob/master/docs/user.md#display-all-post-content sections
You should be able to do what you want now. Re-open the issue, if you encounter some problem
— Reply to this email directly or view it on GitHub https://github.com/LouisBarranqueiro/tranquilpeak-hexo-theme/issues/108#issuecomment-147394812 .
Yeah, tell me :)
Works great! This is how I'd like it to work. I'm a bit worried this might cause you some trouble with other users since the default behavior has changed (excerpts aren't automatic anymore), but I think its the best solution.
yes, it's better than auto excerpt because it give more possibilities to the user. Thank you for created this issue :D
I have a post with these contents:
Which should render like this on the home page:
The GT1 Championship this weekend was a pretty soggy affair, but I got to take some photos…
Click here to see the whole album.
But instead renders like this:
The GT1 Championship this weekend was a pretty soggy affair, but I got to take some photos… Click here to see the whole album.
(Notice no formatting, no image, and no links).
In this case the entire post fits within the excerpt length limit, and I don't have a
<!-- more -->
tag.Am I don't something wrong?