raffaelj/drupal-theme-drinimal

Minimal base theme for Drupal

dev-main 2024-03-08 17:30 UTC

This package is auto-updated.

Last update: 2024-05-08 17:55:20 UTC


README

Minimal base theme for Drupal with some opinionated changes and a few bug fixes.

Why?

Drupal works pretty well out of the box, but it comes with heavy div soup and many unneeded classes or attributes. It also has some serious problems with <link> and <a> markup on the front page - especially in a multilingual setup.

The default minimal theme "stable9" is too bloated. The "starterkit" theme is a child theme of "stable9" and adds more bloat. The "stark" theme is meant for testing and falls back to system templates only.

So I wrote my own base theme with minimal HTML markup and without core CSS.

I also started a thread in the Drupal forum with some more explanations and some struggles on the way to create this minimal theme.

To do / Features

  • reduce div soup
    • [x] remove dialog-off-canvas-main-canvas wrapper div (via hook)
    • [x] remove wrapper <article> around <img /> from media module (via template)
      • [x] Pass alignment class from image wrapper <article> to img tag (via hook)
    • [x] remove wrapper divs .layout-container, .layout-content (via template)
    • see more changes in description of template files
  • remove unneeded HTML attributes
    • [x] remove data-history-node-id attribute from <article> in main content
    • [x] remove data-drupal-selector attribute (via hook)
    • [x] remove data-drupal-link-system-path attr from <a> in menus (via hook)
    • [x] remove redundant role attributes from <main>, <header>, <nav> etc.
    • [x] remove data-history-node-id attribute from <article> (via template)
  • [x] fix node url in node.html.twig if page is front page (for rel="bookmark" link)
  • [x] disable core CSS
    • [x] reimplement .visually-hidden CSS (otherwise the layout breaks, also use clip-path instead of deprecated clip)
  • remove wrong or useless attributes in language switch
    • [x] remove hreflang from <li>
    • [x] remove data-drupal-link-system-path from <li> and <a>
  • fix links to front page
    • [x] in language switch
    • [x] Fix url template variable if node is front page (for rel="bookmark" link)
  • [x] set aria-current="page" and rel="home" to <a> in menus (via hook and templates)
  • [x] remove useless <a id="main-content">, use <main id="main-content"> instead (via template)
  • [x] remove <meta name="Generator" />
  • [x] remove <div data-drupal-messages-fallback class="hidden"></div> (if not logged in)
  • [ ] canonical url of home page points to /node/{id} --> Workaround: install drupal/metatag - fixed without any config, but huge dependency for that simple task
  • [ ] remove unneeded focusable class of skip link --> would require overriding html.html.twig --> not worth it
  • [ ] reduce empty lines in HTML markup (low priority)
  • [x] disable links to untranslated pages in language switch (links to front page with hreflang="x-default" instead) --> might be fixed with language_switcher_extended module - if so, than this should be out of scope
  • [x] fix scrolling to wrong position when using skip link (has position static when focused, but absolute when not --> so jumping to main content causes jumping to "top of main"+"height of skip link"
    • [ ] TODO: open issue in core

out of scope

  • [ ] redirect from / to /en if browser/client language matches --> fixed via rljutils plugin

Installation

install drupal and drush:

mkdir -p my-project && cd my-project
composer create-project drupal/recommended-project .
composer require drush/drush
# call `./vendor/bin/drush` instead of `drush` or
# add drush to $PATH - see https://www.drush.org/12.x/install/
drush site:install

install and enable theme:

# adding the repository can be skipped since 2023-01-15, because it is published on packagist.org
# composer config repositories.drinimal vcs https://codeberg.org/raffaelj/drupal-theme-drinimal

composer require "raffaelj/drupal-theme-drinimal:@dev"

drush theme:install drinimal
drush config:set -y system.theme default drinimal
drush cache:rebuild

Update

composer update
drush cache:rebuild

Copyright and License

Copyright 2023 Raffael Jesche under the GPL-2.0-or-later license.

See LICENSE.txt for more information.

Credits and third-party libraries

I copied and modified a few twig templates from Drupal core modules, which are licensed under GPL-2.0-or-later.