Sitelet https://web.archive.org/web/20220629075340/https://github.com/gohugoio/hugo/issues/3805
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

Use filename as title when it’s not defined in front matter #3805

Open
idealhack opened this issue Aug 15, 2017 · 13 comments
Open

Use filename as title when it’s not defined in front matter #3805

idealhack opened this issue Aug 15, 2017 · 13 comments
Milestone

Comments

@idealhack
Copy link
Contributor

@idealhack idealhack commented Aug 15, 2017

Note: I'm new to Hugo, so If there's a better way about this fell free to correct me.

For now I use {{.File.TranslationBaseName}} in template cause {{.Title}} is empty string. I thought it's better to store it in the title variable, as themes out there are already using it. Also we could use file dates for date and lastmod.

I thought this is a nice feature especially when there're a lot of content files imported from another system.

For myself, I use nvALT to take markdown notes. nvALT has already handle the title and date in this way, now I want to use Hugo for building the website. But maintaining notes metadata by hand is not a good practice IMHO.

What do you think?

This was originally posted at https://discourse.gohugo.io/t/use-filename-as-title-when-its-not-defined-in-front-matter/7965

@bep bep changed the title Use file metadata when they were not defined in front matter Use file base filename whe slug not defined in front matter Aug 15, 2017
@bep bep added this to the v0.27 milestone Aug 15, 2017
@idealhack idealhack changed the title Use file base filename whe slug not defined in front matter Use filename as title when it’s not defined in front matter Aug 15, 2017
@maxandersen
Copy link
Contributor

@maxandersen maxandersen commented Sep 4, 2017

I got a patch that makes this happen, but dependent on the changes in #3762 that in addition to deriving date from filename also fixes how metadata defaults are calculated which is needed to fix title handling. If that PR gets merged in I can easily make a PR for this issue too.

@maxandersen
Copy link
Contributor

@maxandersen maxandersen commented Sep 4, 2017

note I think its worth going a level further and try detect if content has a top level header as defined by markdown, asciidoc or orgmode and use that header if present, if not use filename.

@bep
Copy link
Member

@bep bep commented Sep 4, 2017

note I think its worth going a level further and try detect if content has a top level header as defined by markdown, asciidoc or orgmode and use that header if present,

No, that is too hacky and not worth it.

@maxandersen
Copy link
Contributor

@maxandersen maxandersen commented Sep 4, 2017

No, that is too hacky and not worth it.

too hacky? as compared to try derive from filename ?

It works pretty well in awestruct and others and it has the big plus your blog posts actually render with proper title when shown "raw" in github.

@maxandersen
Copy link
Contributor

@maxandersen maxandersen commented Sep 4, 2017

btw. made the patch before I saw your comment so you can see the idea at #3859

@maxandersen
Copy link
Contributor

@maxandersen maxandersen commented Sep 4, 2017 •

note, the idea is similar to extract toc and summary that tries to parse raw and generated content to derive "metadata".

@bep
Copy link
Member

@bep bep commented Sep 4, 2017 •

Note that the current TOC solution is also considered "hacky and slow" in my book, and will be fixed once Blackfriday 2 is out. We're not doing any regexp magic looking for titles.

Also, I'm not a big fan of pull requests that try to do more than the issue they describe. Do one thing well.

@bep bep removed this from the v0.27 milestone Sep 7, 2017
@bep bep added this to the v0.28 milestone Sep 7, 2017
@bep bep added this to the v0.28 milestone Sep 7, 2017
@bep bep removed this from the v0.27 milestone Sep 7, 2017
@maxandersen
Copy link
Contributor

@maxandersen maxandersen commented Sep 9, 2017

Also, I'm not a big fan of pull requests that try to do more than the issue they describe. Do one thing well.

okey - I've updated patch to just to title based on filename/slug.

I hope this can merged in together with the date fallback which this fix is dependent on (as without it metadata fallback calculation sequences are different whether there is a frontmatter or not )

@bep bep removed this from the v0.28 milestone Sep 21, 2017
@bep bep added this to the v0.29 milestone Sep 21, 2017
@bep bep removed this from the v0.29 milestone Sep 26, 2017
@bep bep added this to the v0.30 milestone Sep 26, 2017
@bep bep removed this from the v0.30 milestone Oct 13, 2017
@bep bep added this to the v0.31 milestone Oct 13, 2017
@bep bep removed this from the v0.31 milestone Oct 30, 2017
@bep bep added this to the v0.32 milestone Oct 30, 2017
@bep bep removed this from the v0.32 milestone Dec 16, 2017
@bep bep added this to the v0.33 milestone Dec 16, 2017
@bep bep removed this from the v0.33 milestone Jan 11, 2018
@bep bep added this to the v0.34 milestone Jan 11, 2018
@bep bep removed this from the v0.34 milestone Jan 22, 2018
@bep bep added this to the v0.88 milestone Jul 30, 2021
@bep bep removed this from the v0.88 milestone Sep 2, 2021
@bep bep added this to the v0.89 milestone Sep 2, 2021
@bep bep removed this from the v0.89 milestone Nov 2, 2021
@bep bep added this to the v0.90 milestone Nov 2, 2021
@Nuc1eoN
Copy link

@Nuc1eoN Nuc1eoN commented Nov 4, 2021

How can I achieve this functionality?

@bep bep removed this from the v0.90 milestone Dec 8, 2021
@bep bep added this to the v0.91.0 milestone Dec 8, 2021
@bep bep removed this from the v0.91.0 milestone Dec 20, 2021
@bep bep added this to the v0.92.0 milestone Dec 20, 2021
@bep bep removed this from the v0.92.0 milestone Jan 12, 2022
@bep bep added this to the v0.93.0 milestone Jan 12, 2022
@bep bep removed this from the v0.93.0 milestone Mar 1, 2022
@bep bep added this to the v0.94.0 milestone Mar 1, 2022
@bep bep removed this from the v0.94.0 milestone Mar 9, 2022
@bep bep added this to the v0.95.0 milestone Mar 9, 2022
@bep bep removed this from the v0.95.0 milestone Mar 15, 2022
@bep bep added this to the v0.96.0 milestone Mar 15, 2022
@bep bep removed this from the v0.96.0 milestone Mar 24, 2022
@bep bep added this to the v0.97.0 milestone Mar 24, 2022
@bep bep removed this from the v0.97.0 milestone Apr 13, 2022
@bep bep added this to the v0.98.0 milestone Apr 13, 2022
@bep bep removed this from the v0.98.0 milestone Apr 28, 2022
@bep bep added this to the v0.99.0 milestone Apr 28, 2022
@bep bep removed this from the v0.99.0 milestone May 24, 2022
@bep bep added this to the v0.100.0 milestone May 24, 2022
@bep bep removed this from the v0.100.0 milestone May 31, 2022
@bep bep added this to the v0.101.0 milestone May 31, 2022
@bep bep removed this from the v0.101.0 milestone Jun 16, 2022
@bep bep added this to the v0.102.0 milestone Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment