Customize Template Per Blog Tag for SEO

I’ve got a blog with about 100 posts, 2 categories, and 10 tags. The categories and tags share a single layout and template.

What I’d like is to be able to have custom frontmatter and body h1 and h2 for each category and topic, so that when the pages are indexed they don’t have duplicate meta title, meta description, h1, and h2.

Is there a way to do this? I don’t want to sacrifice all the dynamism that’s built into the tagging system by abandoning that system for something static. I thought maybe with nested layouts, but I couldn’t figure out a way. Any help?

The standard pattern here is to use Content_For and then yield_content in the meta tags.

This is my helper to allow for all possibilites and fallbacks

##
# Configuration
# Allows the user to have full control over the aspects of the site structure.
# This is particularly useful for meta data abstraction.
#
# @usage
# -# Configuration
# = configuration( "title", "navigation" )
#
# A configuration constant can come from four places (highest priority first)
# - Yield content
# - Front matter
# - Locale
# - Data file
#
# @todo Need to delve deeper into the config of the data file at the moment one deep
##
def configuration( id, file = "config" )

    # Variable
    cp = current_page.data

    # Front matter meta
    m = cp.stub ? "meta.#{ cp.stub }" : cp

    # Need a fall back for meta to use the Global settings meta.author for instance

    # Data file lookup or default
    # Need to specify the named file or will assume config
    localData = I18n.exists?( :"#{ m }.#{ id }" ) ? :"#{ m }.#{ id }" : data[ file ][ id ] ? data[ file ][ id ] : :"meta.#{ id }"

    # Front locale finds in the front matter or in the locale file (requires a stub)
    frontMatter = cp[ id ] ? m[ id ] : localData

    # Finds the ID based on the content_for output helper
    contentFor = content_for?( :"#{ id }" ) ? yield_content( :"#{ id }" ) : frontMatter

    string contentFor

end
1 Like