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

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

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

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

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

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

@maxandersen
Copy link
Contributor

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 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 modified the milestones: v0.27, v0.28 Sep 7, 2017
@maxandersen
Copy link
Contributor

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 modified the milestones: v0.28, v0.29, v0.30 Sep 21, 2017
@bep bep modified the milestones: v0.30, v0.31 Oct 13, 2017
@bep bep modified the milestones: v0.31, v0.32 Oct 30, 2017
@bep bep modified the milestones: v0.32, v0.33 Dec 16, 2017
@bep bep modified the milestones: v0.33, v0.34 Jan 11, 2018
@bep bep removed this from the v0.34 milestone Jan 22, 2018
@bep bep modified the milestones: v0.114.0, v0.115.0 Jun 13, 2023
@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
@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