Search code examples
pelican

Limit number of tags in content


there is that old blog post to get a list of categories and tags from the content.

I only found tag_cloud as the only plugin dealing with tags no further mention in the documentation

Is there any way to limit the usable tags e.g. through the configs ?


Solution

  • One option is you can define a ALLOWED_TAGS variable in pelicanconf.py to contain the tags that you want to allow, then in places where tags are placed you can add a JINJA if block to allow only these tags

    #pelicanconf.py
    
    ...
    
    ALLOWED TAGS = ("tag1", "tag2", "tag3", tag4") 
    

    Example of generating tags for an article below

    <div class="article-tags">
        {% for tag in article.tags %}
        {% if tag in ALLOWED_TAGS %}
        <a href="/tags/{{tag}}"><{{tag}}</span></a>
        {% endif %}
        {% endfor %}
    </div>