cryogen-project / cryogen-core

Cryogen's core
Eclipse Public License 1.0
69 stars 62 forks source link

Expose plaintext `description` to pages/posts #126

Closed holyjak closed 4 years ago

holyjak commented 4 years ago

so that they can use it in <meta name=description ..> and for previews on Fb/Slack/.. e.g. via <meta property=og:description ...>.

The new post/page :description is derived from the HTML previews, by default including text from p and hN tags.

You want to use it as {{post.description}} in a template.

Updating templates

When this is merged, we should update templates as follows:

<!-- base.html: -->
...
       <title>{{title}}{% block subtitle %}{% endblock %}</title>
        {% block meta %}
        <meta name="description" content="{{description}}">
        <meta name="keywords" content="">
        {% endblock %}
...
<!-- post.html: -->
{% extends "/html/base.html" %}
{%block subtitle %}: {{post.title}}{% endblock %}
{% block meta %}
<meta name="keywords" content="{% for tag in tags %}{{tag.name}}{% if not forloop.last %},{% endif %}{% endfor %}">
{% if post.description %}
<meta name="description" content="{{post.description}}">

{% comment %}{# OpenGraph tags #}{% endcomment %}
<meta property="og:url" content="{{site-url}}{{uri}}" />
<meta property="og:title" content="{{post.title}}" />
<meta property="og:description" content="{{post.description}}">
<meta property="og:type" content="article" />
{% endif %}
{% endblock %}
{% endblock %}
...
<!-- page.html: -->
{% extends "/html/base.html" %}
{% block subtitle %}: {{page.title}}{% endblock %}
{% block meta %}
{% if page.description %}
<meta name="description" content="{{page.description}}">

{% comment %}{# OpenGraph tags #}{% endcomment %}
<meta property="og:url" content="{{site-url}}{{uri}}" />
<meta property="og:title" content="{{page.title}}" />
<meta property="og:description" content="{{page.description}}">
<meta property="og:type" content="article" />
{% endblock %}
...

Updating docs

We need to update the docs to mention that the :post|:page :description is available, to document the config option description-include-elements and its default of #{:p :h1 :h2 :h3 :h4 :h5 :h6}, and to document that you can specify a custom :description in the page metadata block or :description false to disable it.

lacarmen commented 4 years ago

LGTM. Will you be doing the template and doc updates as well? I'm happy to merge this in now, but want to hold off on publishing to clojars until we get those two things done.

holyjak commented 4 years ago

The docs and templates PRs 👆