Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Hugo to parse "plain" Markdown #6098

Open
lucperkins opened this issue Jul 19, 2019 · 19 comments
Open

Allow Hugo to parse "plain" Markdown #6098

lucperkins opened this issue Jul 19, 2019 · 19 comments

Comments

@lucperkins
Copy link

lucperkins commented Jul 19, 2019

I work on a lot of OSS documentation projects, and I strive to use Hugo in all of them (I can point to 20+ projects that I've used Hugo for). One of the downsides of Hugo is this: many people want to be able to use a directory full of "bare" Markdown in conjunction with Hugo, but they can't, which means that they need to provide some kind of "bridging" solution that converts that Markdown into something consumable by Hugo.

By "bare" Markdown I mean Markdown with:

  1. No page metadata specifying the title, params, tags, etc.
  2. Links to /docs/foo.md rather than /docs/foo (because the links are to Markdown pages, not rendered HTML pages).

So what usually happens is that people create some kind of build pipeline using tools like Gulp.js that adds page metadata, converts links, etc. It would be fantastic if Hugo provided you the option to:

  1. Derive the document title from, say, the first <h1> or maybe the first header.
  2. Automatically convert /foo.md links to /foo (or even make the .md configurable).

Imagine the ability to do this (just spitballing here):

hugo server --convertLinks "md" --inferTitle --source my-github-repo

As with issue #6095, I'd be happy to take on this work if others think it's a good idea. I'm not sure how useful this would be to others. I do know that it would be immensely useful to me and I can think of many projects that would benefit.

@onedrawingperday
Copy link
Contributor

Basically this issue is about allowing markdown content without front matter and I also think that this would be a very useful feature in Hugo.

@lucperkins
Copy link
Author

@onedrawingperday Yes, that's precisely it. I work on many documentation projects in which the front matter contains nothing but a title, which could be inferred according to a hierarchy like this:

  1. Front matter
  2. If not in front matter, use first header
  3. If no headers, use filename

@stale
Copy link

stale bot commented Nov 22, 2019

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@stale stale bot added the Stale label Nov 22, 2019
@bep bep added the Keep label Nov 22, 2019
@stale stale bot removed the Stale label Nov 22, 2019
@DewofyourYouth
Copy link

sounds doable. i'll take a look at it.

@bep
Copy link
Member

bep commented Jan 30, 2020

@DewofyourYouth I think we need to talk a little about the "what" here first.

This issue is a little bit old. From when @lucperkins created it I think the core of the problem is already solved, see https://github.com/bep/portable-hugo-links

What's left in the above is the document title.

Derive the document title from, say, the first <h1> or maybe the first header.

Which would mean a repeated value, not really useful. Most Markdown docs start at h2.

@lucperkins
Copy link
Author

@bep In my experience, most people use an h1 at the very top of the document to specify the title when they’re not specifying it via metadata.

@DewofyourYouth
Copy link

Yeah, I was going to ask that the issue seemed to be mostly solved.
OK, so if I understand correctly, what we might want to do is just to check for the first h1 on docs without frontmatter - and if there is one to use it as the title?

@lucperkins
Copy link
Author

@DewofyourYouth I’m more proposing a render hook that would enable you to potentially determine the title via something that isn’t front matter. So you could have logic like “if the title is set via front matter use that, otherwise use the first h1 in .Content, otherwise use a titleized version of the filename.”

@DewofyourYouth
Copy link

OK. Sounds like a plan. @bep does that work?
@lucperkins could you share an example of one of these gulpfiles you were talking about so I can get a sense of what kind of edge cases I should be thinking of? (If not I'll just use my imagination or find one.)

@lucperkins
Copy link
Author

lucperkins commented Jan 30, 2020

@DewofyourYouth Sadly no, as I’ve put in a bajillion hours to successfully eliminate them 😀 But I think you fully grasp the problem already. Those scripts really only did two things, changing /foo.md to /foo and inserting front matter. The first has been solved via render hooks, and allowing for zero front matter would solve the second one.

So yeah, earlier in this thread I was envisioning something more hardcoded (“infer title via first header”) but later in the thread I realized that render hooks could enable you to infer the title however you like. And maybe even allow you to infer other front matter items (date, weight, etc) as well.

@bep
Copy link
Member

bep commented Jan 30, 2020

OK. Sounds like a plan. @bep does that work?

We currently parse the metadata early and the content lazily and only if it's used. I'm not giving up on that for this feature, so we need to think about it. I have my plate filled with other stuff, so this needs to wait.

@bep bep added this to the v0.66 milestone Jan 30, 2020
@ghost
Copy link

ghost commented Feb 7, 2020

I would absoluteley appreciate this feature!

@bep bep modified the milestones: v0.66, v0.67 Mar 2, 2020
@bep bep modified the milestones: v0.67, v0.68 Mar 9, 2020
@edrex
Copy link

edrex commented Mar 16, 2020

I would like to use hugo for rendering my plain markdown notes/journals. My current experience is that plain markdown pages are rendered (at least with my config) but don't show up in lists.

We currently parse the metadata early and the content lazily and only if it's used.

Makes sense. How about just falling back to a title-cased version of the filename (eg "the-story-of-pie" => "The Story of Pie"), for the moment? @bep

I'd be happy to have a go at impl if so.

hi @lucperkins :)

@edrex
Copy link

edrex commented Mar 16, 2020

don't show up in lists

Actually, they do, it's just that they

a. have no title so the <a doesn't render
b. are out of order since they don't have a date

I was able to get entries without a title to show by replacing {{ .Title }} with {{ .Title | default .File.BaseFileName }} in my list.html.

The other barrier to this being useful is lack of date ordering. Not sure if this can be worked around in templates.

@bep bep modified the milestones: v0.68, v0.69 Mar 20, 2020
@onedrawingperday
Copy link
Contributor

onedrawingperday commented Mar 24, 2020

Apparently it is possible to make Hugo parse Markdown without front matter by using Front Matter Cascade

See this forum post and the one below for the details:
https://discourse.gohugo.io/t/what-is-required-to-make-markdown-get-picked-up/24191/8

cc: @bep

@bep bep modified the milestones: v0.69, v0.70 Apr 8, 2020
@bep bep modified the milestones: v0.70, v0.71 Apr 28, 2020
@bep bep removed this from the v0.71 milestone May 18, 2020
@bep bep modified the milestones: v0.115.0, v0.116.0 Jun 30, 2023
@bep bep modified the milestones: v0.116.0, v0.117.0 Aug 1, 2023
@bep bep modified the milestones: v0.117.0, v0.118.0 Aug 30, 2023
@bep bep modified the milestones: v0.118.0, v0.119.0 Sep 15, 2023
@bep bep modified the milestones: v0.119.0, v0.120.0 Oct 4, 2023
@bep bep modified the milestones: v0.120.0, v0.121.0 Oct 31, 2023
novad03 pushed a commit to novad03/k8s-meta that referenced this issue Nov 25, 2023
When I try to run `hugo server` right now, I get the following error:

  Error: Error building site: "/home/rbryant/go/src/github.com/metallb/metallb/website/content/_header.md:1:1": plain HTML documents not supported

It seems like this is an issue with a more recent version of hugo.
I'm using the following version from a Fedora package:

  Hugo Static Site Generator v0.80.0/extended linux/amd64 BuildDate: unknown

This change is based on a suggested workaround in the following issue:

  gohugoio/hugo#7296

The workaround seems harmless, and may no longer be needed if the
following issue gets resolved at some point in the future:

  gohugoio/hugo#6098
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
@bep bep modified the milestones: v0.125.0, v0.126.0 Apr 23, 2024
@bep bep modified the milestones: v0.126.0, v0.127.0 May 15, 2024
@bep bep modified the milestones: v0.127.0, v0.128.0 Jun 8, 2024
@bep bep modified the milestones: v0.128.0, v0.129.0 Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants