getnikola / nikola

A static website and blog generator
https://getnikola.com/
MIT License
2.6k stars 444 forks source link

Generated front page contains one `<h1>` for each post, I wish they were `<h2>` #3708

Open tartley opened 1 year ago

tartley commented 1 year ago

Environment

Python Version: 3.10.12 Nikola Version: 8.2.4 Operating System: Pop!_OS 22.04 (derived from Ubuntu 22.04)

Description

My generated front page has several <h1> tags in it, one for each included post. I want them to be <h2> tags instead.

Only using a single <h1> is recommended as a best practice (e.g. here in Mozilla developer network). In particular, I'm trying to register my Nikola site with Bing webmaster tools, so that it will get indexed and appear in search results. To be indexed, a page must only have at most one <h1> tag. So I can't get my front page indexed.

I tried editing my conf.py, uncommenting either PANDOC_OPTIONS = ['--base-header-level=2'], or DEMOTE_HEADERS = 1, but this has not had any effect.

(Incidentally, grepping the code for 'DEMOTE_HEADERS' only finds this instance. Is this option currently used?)

sukiletxe commented 1 year ago

Iirc both options are only used in headings of the bodies of posts.

I do agree with this sentiment, but this creates another problem, what about posts with subheadings? How do we accomodate both "headings should be hierarchical" and "only one h1 per page"?

tartley commented 1 year ago

A fair question.

I had imagined, when I saw the conf.py options to demote headings, that they would demote all headings by the same amount. Hence h2 would become h3, and the max (h7?) would become a standalone para of regular text.

Presumably though, this question is independent of the issue I'm raising. The demotion of sub-headers is "handle demotion correctly", and needs to be done right on individual posts too, while this issue is "apply the demotion on the front page as well as individual posts."

Kwpolska commented 12 months ago

This single-<h1> rule is a bit nonsensical IMO, and Bing should not reject webpages for things like this; they certainly didn’t mind indexing Nikola’s blog.

If you want to follow this rule, you would need to change your templates so that there is a <h1> associated with the site title (there isn’t in bootstrap themes, and a <h1> in the menu bar would be weird and hard to style — should our pages have no <h1>s at all if we apply the rule?), and post/page titles are <h2>. Afterwards, setting DEMOTE_HEADERS = 2 should convert first-level headers in input to <h3> and the outlines would match the standards.

tartley commented 12 months ago

Thanks for the input. FWIW I mis-spoke earlier - Bing webmaster tools produces an error about the multiple h1 tags, but once I cleared up other errors, it will now index the page. So this doesn't block indexing after all.