I have a following use case:
I’d like to extract certain paragraphs from typical README.md files from some of my projects and reuse them in my webpage. These may be e.g. short project descriptions to be used in a list of projects.
I can use unionfs to bring those README.md files into a hugo project no-problem. But what is the best approach to extracting a heading of a certain name and its contents (i.e. everything until a next heading) from markdown files?
I haven’t found any built-in functionality but I’m new to Hugo. Is there such functionality? If not should I try to use templates? If so, should I use them before or after converting the markdown to HTML? If not should I develop/find some external markdown parser and try to integrate it to Hugo as some kind of plugin? Does Hugo even have a plugin system?
I’ve found only tangential related problems after searching this forum. Is my use-case weird?
Thanks
No, not out out the box. (also including a complete file will need a few lines of code). If you are interested only in the beginning of the file you could read on Content Summaries
Yes - you mention “in a list of projects”. Implementing a partial template will be the way to go.
If you later also want to include content to your markdown file at certain places you need a custom shortcode to call it from Markdown. Here you could reuse the template you wrote for including the snippet in the list page.
No, without hacking there’s no way to add external libraries or tools (other than already provided)
maybe - depending on included content, your theme, and use case. In your case of a simple README. I would go with the markdown.
HTML may include styles, define html tags used by css, … and your current page is a list page that may use different ones. You could get side effects. and unwanted stylings…
Implementation
usually done by either
looping over included lines and check for begin and end patterns in your case ^#+ HEADING NAME and then ^#+for the end.
a regular expression matching a heading with name up to the next heading or endof file.