Comments (13)
It looks like Blogdown knits to html, although the partials are properly processed features like summary and table of contents are not available. The <!--more-> processing command is included as a regular html comment.
I modified my template to use description if available, because the first 70-words was messy.
{{ if .Description }}
{{ .Description }}
{{ else }}
{{ .Summary | plainify | safeHTML }}
{{ end }}
{{ if .Truncated }}
from blogdown.
Right. It is up to the specific Hugo theme whether/how you can customize the summary. Some themes support the summary
field in YAML, such as https://github.com/gcushen/hugo-academic and https://github.com/digitalcraftsman/hugo-icarus-theme You can write something like
---
title: "My Post"
summary: "A custom summary of my post."
---
from blogdown.
@andrie -- thank you very much for the simple replacement solution for tranquilpeak
to allow use of a description
field in the YAML.
In case anyone finds this solution, for the current version 0.4.3-BETA
, the replacement in themes\hugo-tranquilpeak-theme\layouts\_default\summary.html
has been simplified a bit:
Replace line 43:
{{ .Summary }}
with:
{{if .Description }}
{{ .Description }}
{{ else }}
{{ .Summary }}
{{ end }}
Edited to add:
Per @SteveRxD, the following change (using the YAML parameter 'summary' instead of 'description', and I think applying markdown formatting processing) from here might be a better replacement consistent with future versions of tranquilpeak
:
{{ if .Params.Summary }} {{ .Params.Summary | markdownify }} {{ else }} {{ .Summary }} {{ end }}
from blogdown.
@ProQuestionAsker Hi Amber, I am using the same theme you are using for your website/blog. Could you please tell me where to modify the template as @tovare suggested?
from blogdown.
Sorry for the delay here @trefoil-ml and @lyons7
I had to add the description code as suggested by @tovare to both the "Portfolio" partial file and the "list" partial file. You'll find the updated versions in the repo for my site:
Then you just add a description
feature to your YAML header. So the header for my blog post looks like this:
---
date: "2016-12-19"
title: "Making a Website Using Blogdown, Hugo, and GitHub pages."
type: "post"
showonlyimage: true
draft: false
weight: 0
author: "Amber Thomas"
image: "blog/img/SiteTutorial.jpg"
description: "Wonder how I set up this website using just GitHub pages, Hugo, and RStudio package blogdown? This tutorial walks you through every step."
---
Hope that helps!
from blogdown.
Thank you so much @ProQuestionAsker! Works like a charm 🥇
from blogdown.
@ProQuestionAsker, @yihui another approach I use with success that fullfills @mkhezr 's requirement to preserve the html is using replaceRE
.
My context is I use this to generate summaries for posts on index, where each post consists of a summary and then a content, divided by the standard <!--more-->
. This means for me that to produce a summary, I replace everything after that with empty string:
<p class = "summary">
{{ replaceRE "(?s)(<!--more-->.*)" "" .Content | safeHTML }}
</p>
This uses regular expressions to
- replace everything in
.Content
after<!--more-->
with an empty string""
- note the
(?s)
flag that lets.
match\n
(newline)
You could of course use any other string for the splitting, or any other pattern that better suits your needs as regular expressions are a very flexible tool.
References:
from blogdown.
@trefoil-ml You ever figure out where to modify the template?
from blogdown.
@tovare Brilliant!! I had tried manually adding a .Summary field but hadn't thought to add a .Description!
Works like a charm. Thank you!
from blogdown.
The equivalent solution for the tranquilpeak
theme is to modify the file themes\hugo-tranquilpeak-theme\layouts\_default\summary.html
as follows:
Replace line 44:
{{ printf "%s" .Summary | markdownify }}
with:
{{if .Description }}
{{ printf "%s" .Description }}
{{ else }}
{{ printf "%s" .Summary | markdownify }}
{{ end }}
from blogdown.
You guys are awesome! I could do the same proposed by @tovare, as explained by @ProQuestionAsker, in both files 'layouts/partials/recent_posts.html' and '/layouts/_default/list.html' for hugo-universal-theme. It works like a charm, thanks!!
from blogdown.
I want to request to reopen this issue because although the workarounds above allow for customizing the summary text, they still leave the following issue unresolved.
One of the things that hugo does with the <!--more-->
summary divider is that it keeps the html before the divider intact. This means that the summary that is generated is not just text but could include other elements such as figure. Whereas when the divider is not used, first all html is striped and then the 70 word summary is generated. (See Hugo's documentation)
I am using the Jane theme and I wish the summaries to include header photos which means that we need to signal hugo with a <!--more-->
tag to preserve the html. maybe a helper function similar to blogdown::shortcode will do the work.
@yihui I would be happy to provide examples and more details.
from blogdown.
@jozefhajnala Many thanks for sharing your solution!
from blogdown.
Related Issues (20)
- For error `could not find function "parser"`: fail more gracefully HOT 3
- Issue with site formatting with blogdown::build_site(). HOT 3
- Unable to serve site after updates HOT 6
- modelDown::modelDown() deleted all files in my output folder??!! HOT 1
- Home directory does not exist in HUGO academic-theme HOT 1
- Upkeep for blogdown
- Rmd files rendering with formatting issues HOT 7
- blogdown:::new_post_addin() should check for hugo first HOT 1
- Blogdown don’t supports multiple-column rmarkdown HOT 8
- Unable to create new posts HOT 2
- Missing website menu bar buttons when using blogdown to render web pages HOT 3
- Wrong relative links on the pkgdown site HOT 2
- allow use of hugo.toml for config [FR] HOT 3
- Error building site with hugo-apero theme HOT 5
- Build site with updated Hugo HOT 2
- shortcode doesn't display with leaflet map in the same post HOT 4
- Rmd - interactive map with tmap does not display HOT 5
- trialblogdown HOT 1
- Blogdown starting error and rmd render not working HOT 1
- unable to embed Rmd file in html output HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blogdown.