getnikola / nikola

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

OpenGraph Data in Base Template #3798

Open Xaldew opened 5 hours ago

Xaldew commented 5 hours ago

Requested Feature: (short description)

OpenGraph Metadata for the primary/main index page.

Related Area: (eg. tasks, compilers, configuration, templates…)

N/A

Do you want to contribute this yourself as a pull request? (don’t worry about it if you don’t want to/can’t — someone else can take care of it)

Does this feature affect backwards compatibility? If yes, in what way?

Not as far as I know.

Rationale and full description: (why should it be added to Nikola?)

It's fairly common to link to the index page rather than to individual posts, hence it makes sense to generate OpenGraph meta-data for that page as well. I'm not sure exactly how difficult it is to propagate this to all themes, but at least for the Bootstrap theme that I am using, it was straightforward to extend to base_template.tmpl with:

    <!-- ${pagekind} -->
    %if 'index' in pagekind or 'main_index' in pagekind:
      <meta property="og:site_name" content="${blog_author}">
      <meta property="og:title" content="${blog_title|h}">
      <meta property="og:url" content="${abs_link(permalink)}">
      <meta property="og:description" content="${description|h}">
      <meta property="og:image" content="${abs_link('/assets/images/phoenix_logo.png')}">
      <meta property="og:type" content="article">
    %endif

Naturally, the asset image link would need to be changed somehow, perhaps by using the DEFAULT_PREVIEW_IMAGE, but other than that, the above should be pretty much usable as-is in any HTML template.

Kwpolska commented 2 hours ago

If it were added, it should probably be added to index.tmpl.

I’m not sure how useful it is — is the link display significantly improved in that case?