All Projects → dirkolbrich → Hugo Theme Tailwindcss Starter

dirkolbrich / Hugo Theme Tailwindcss Starter

Licence: mit
Starter files for a Hugo theme with Tailwindcss

Projects that are alternatives of or similar to Hugo Theme Tailwindcss Starter

bento
A minimalist theme for Hugo, build with Tailwind CSS - https://bento-hugo-theme.netlify.app/
Stars: ✭ 58 (-68.98%)
Mutual labels:  hugo, tailwindcss
eleventy solo starter njk
Further development suspended as of 2021-09-11. Please refer instead to https://www.11ty.dev/docs/starter/ for a wide selection of other Eleventy starter sets.
Stars: ✭ 22 (-88.24%)
Mutual labels:  starter-template, tailwindcss
Minimalist-Blog
Tailwind CSS Starter Template - Minimalist Blog
Stars: ✭ 21 (-88.77%)
Mutual labels:  starter-template, tailwindcss
air
A hyper-minimal WordPress starter theme for developers built with Tailwind CSS.
Stars: ✭ 45 (-75.94%)
Mutual labels:  starter-template, tailwindcss
Nordic Store
Tailwind CSS Starter Template - Nordic Shop / Store
Stars: ✭ 61 (-67.38%)
Mutual labels:  starter-template, tailwindcss
YATAS
Yet Another Tailwind Alpine Starter
Stars: ✭ 18 (-90.37%)
Mutual labels:  starter-template, tailwindcss
hugo-starter-tailwind-basic
A basic and simple to set up Hugo with TailwindCSS starter project.
Stars: ✭ 80 (-57.22%)
Mutual labels:  hugo, tailwindcss
tailwind-react-next.js-typescript-eslint-jest-starter
Starter template for building a project using React, Typescript, Next.js, Jest, TailwindCSS and ESLint.
Stars: ✭ 80 (-57.22%)
Mutual labels:  starter-template, tailwindcss
Admin Template Night
Tailwind CSS Starter Template - Admin Dashboard Template (Night Mode)
Stars: ✭ 40 (-78.61%)
Mutual labels:  starter-template, tailwindcss
Gridsome Starter Liebling
Grisome starter based on Ghost Liebling and tailwindcss.
Stars: ✭ 23 (-87.7%)
Mutual labels:  starter-template, tailwindcss
Hugo Eureka
Eureka is a feature-rich and highly customizable Hugo theme.
Stars: ✭ 239 (+27.81%)
Mutual labels:  hugo, tailwindcss
Ghostwind
Tailwind CSS Starter Template - Ghostwind (Ghost Casper theme in Tailwind CSS)
Stars: ✭ 89 (-52.41%)
Mutual labels:  starter-template, tailwindcss
top-nuxt3
Full stack Nuxt 3 Template starter with Supabase and Tailwindcss
Stars: ✭ 59 (-68.45%)
Mutual labels:  starter-template, tailwindcss
Landing Page
Tailwind CSS Starter Template - Landing Page
Stars: ✭ 444 (+137.43%)
Mutual labels:  starter-template, tailwindcss
Profile Card
Tailwind CSS Starter Template - Profile Card (Single page website for your profile/links)
Stars: ✭ 69 (-63.1%)
Mutual labels:  starter-template, tailwindcss
Admin Template
Tailwind CSS Starter Template - Admin Dashboard Template
Stars: ✭ 160 (-14.44%)
Mutual labels:  starter-template, tailwindcss
Hugo Sustain
🦁 Personal blog theme built with Bootstrap, powered by Hugo.
Stars: ✭ 165 (-11.76%)
Mutual labels:  hugo
Leaguestats
📈 League of Legends Stats Web App
Stars: ✭ 172 (-8.02%)
Mutual labels:  tailwindcss
Goorgeous
[DEPRECATED] A go org syntax parser to html
Stars: ✭ 166 (-11.23%)
Mutual labels:  hugo
Staticman
💪 User-generated content for Git-powered websites
Stars: ✭ 2,098 (+1021.93%)
Mutual labels:  hugo

Hugo Starter Theme with Tailwind CSS

Starter files for a Hugo theme with Tailwind CSS.

  • set up to use Tailwind CSS - v2.0+
  • includes the @tailwindcss/typography plugin for styling of markdown content
  • use Hugo Pipes to build and load css based on dev or build environment
  • purge unused css classes with PurgeCSS for build, but not in dev
  • works as separate theme repo or as a local theme folder within a Hugo site
  • basic template setup with an index page, an about page and a posts category
  • responsive navigation header with minimal javascript with pure css to hide the nav on small screens
  • to keep that s***er down, the theme features a sticky footer
  • included helper partials to show Hugo parameters and Tailwind CSS breakpoints during development

Live long and code.

What this theme is NOT

This theme is a starter setup theme to aid in developing Hugo themes using the Tailwind CSS framework. It is not a standalone theme ready to use.

Prerequisites

Make sure to install postcss-cli and autoprefixer globally in your environment, as Hugo Pipe’s PostCSS requires it. This is mentioned in the Hugo Docs.

npm install -g postcss-cli
npm install -g autoprefixer

Make sure to use a minimum Hugo version of v0.69.0 and above.

Set the writeStats option in your Hugo config file, so that purging of CSS classes works in production. See /exampleSite/config.toml as a guideline.

[build]
  writeStats = true

Basic usage to develop a separate Theme repo

  • clone and rename the repo
git clone https://github.com/dirkolbrich/hugo-theme-tailwindcss-starter new-theme-name
  • to make that theme your own, switch into the newly created folder, remove the git history from this starter repo and initiate a new git repo
cd new-theme-name
rm -rf .git
git init
  • now install the necessary node packages
npm install
  • edit the config.toml file in exampleSite/ to reflect the new-theme-name
# in config.toml
theme = "new-theme-name" # your new theme name here
  • start a server to develop with exampleSite
hugo server -s exampleSite --themesDir=../.. --disableFastRender

Usage directly within a Hugo repo as a theme package

  • start a new Hugo site
hugo new site new-site
  • switch into the theme folder an clone the starter repo
cd new-site/themes
git clone https://github.com/dirkolbrich/hugo-theme-tailwindcss-starter new-theme-name
  • switch into the newly created theme folder, remove the git history from this starter repo and install the node packages
cd new-theme-name
rm -rf .git
npm install
  • edit the config.toml file in new-site/ to reflect the new-theme-name
# in config.toml
theme = "new-theme-name" # your new theme name here
  • switch to the root of the new-site repo and start a server to view the index site
cd new-site
hugo server --disableFastRender

Your content should go into new-site/content, the development of the site layout is done within new-site/themes/new-theme-name/layout.

Helpers

Included are the following helpers for the development phase (not visible in production):

  • /partials/dev-parameters.html, which shows basic Hugo page parameters
  • /partials/dev-size-indicator.html, which displays a floating circle in the upper right corner to indicate the Tailwind CSS responsive breakpoints

If you don't need any of these helpers anymore, just delete the corresponding line from /layouts/_default/baseof.html.

Deploy to Netlify

If you use this starter theme and want to deploy your site to Netlify, you MAY encounter a build error which contains the following line:

ERROR {your deploy time here} error: failed to transform resource: POSTCSS: failed to transform "css/styles.css" (text/css): PostCSS not found; install with "npm install postcss-cli". See https://gohugo.io/hugo-pipes/postcss/

That is, Netlify doesn't know the npm dependencies of this starter theme yet. For this to fix, please add a package.json file to the root of your repo with the content:

{
    "name": "my-site",
    "version": "0.0.1",
    "description": "that is my-site",
    "repository": "https://github.com/you/my-site",
    "license": "MIT",
    "devDependencies": {
        "@fullhuman/postcss-purgecss": "^3.1.3",
        "@tailwindcss/typography": "^0.3.1",
        "autoprefixer": "^10.2.0",
        "postcss": "^8.2.3",
        "postcss-cli": "^8.3.1",
        "postcss-import": "^14.0.0",
        "tailwindcss": "^2.0.2"
    },
    "browserslist": [
        "last 1 version",
        "> 1%",
        "maintained node versions",
        "not dead"
    ]
}

This introduces the dependencies Tailwind CSS and PostCSS need, Netlify will run the installation automatically on deploy.

Environment variables

To make the distinction between development and production environments work, add an environment variable HUGO_ENV = "production" to your site settings under SettingsBuild & deployEnvironment.

Or use a netlify.toml for a file-based configuration.

How does that work anyway?

Within postcss.config.js a purgecss function is defined, which is only called based on the environment variable HUGO_ENVIRONMENT === 'production'.

const themeDir = __dirname + '/../../';

const purgecss = require('@fullhuman/postcss-purgecss')({
    // see https://gohugo.io/hugo-pipes/postprocess/#css-purging-with-postcss
    content: ['./hugo_stats.json'],
    defaultExtractor: (content) => {
        let els = JSON.parse(content).htmlElements;
        return els.tags.concat(els.classes, els.ids);
    }
})

module.exports = {
    plugins: [
        require('postcss-import')({
            path: [themeDir]
            }), 
        require('tailwindcss')(themeDir + 'assets/css/tailwind.config.js'),
        require('autoprefixer')({
            path: [themeDir],
            grid: true
        }),
        ...(process.env.HUGO_ENVIRONMENT === 'production' ? [purgecss] : [])
    ]
}

During the build process Hugo Pipes checks this variable too and build the styles.css with some additional minification. This snippet is located in /layouts/partials/head.html.

{{ $styles := resources.Get "css/styles.css" | postCSS (dict "config" "./assets/css/postcss.config.js") }}
{{ if .Site.IsServer }}
    <link rel="stylesheet" href="{{ $styles.RelPermalink }}">
{{ else }}
    {{ $styles := $styles| minify | fingerprint | resources.PostProcess }}
    <link rel="stylesheet" href="{{ $styles.Permalink }}" integrity="{{ $styles.Data.Integrity }}">
{{ end }}

Reference

Documentation for Hugo's PostCSS setup.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].