Code Monkey home page Code Monkey logo

Comments (13)

tovare avatar tovare commented on July 28, 2024 4

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.

yihui avatar yihui commented on July 28, 2024 4

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.

jhchou avatar jhchou commented on July 28, 2024 3

@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.

trefoil-ml avatar trefoil-ml commented on July 28, 2024 2

@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.

ProQuestionAsker avatar ProQuestionAsker commented on July 28, 2024 2

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:

Portfolio: https://github.com/ProQuestionAsker/ProQuestionAsker.github.io/blob/07467d475eed5496138d32cd3bc65cdab84b6c8d/themes/hugo-creative-portfolio-theme/layouts/partials/portfolio.html#L35

List: https://github.com/ProQuestionAsker/ProQuestionAsker.github.io/blob/07467d475eed5496138d32cd3bc65cdab84b6c8d/themes/hugo-creative-portfolio-theme/layouts/_default/list.html#L54

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.

lyons7 avatar lyons7 commented on July 28, 2024 2

Thank you so much @ProQuestionAsker! Works like a charm 🥇

from blogdown.

jozefhajnala avatar jozefhajnala commented on July 28, 2024 2

@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.

lyons7 avatar lyons7 commented on July 28, 2024 1

@trefoil-ml You ever figure out where to modify the template?

from blogdown.

ProQuestionAsker avatar ProQuestionAsker commented on July 28, 2024

@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.

andrie avatar andrie commented on July 28, 2024

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.

cmcouto-silva avatar cmcouto-silva commented on July 28, 2024

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.

mkhezr avatar mkhezr commented on July 28, 2024

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.

yihui avatar yihui commented on July 28, 2024

@jozefhajnala Many thanks for sharing your solution!

from blogdown.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.