Giter VIP home page Giter VIP logo

hugo-flex's Introduction

Hugo Flex

A lightweight Hugo theme leveraging CSS Flexbox.

This theme is verified to work with Hugo versions v0.122.0–v0.125.3.

Features

Optional features:

Example

The demo site is built from the hugo-flex-demo repository.

A complete starter template specifically made for this theme is also available at scivision/hugo-flex-example.

Installation

  1. Install Hugo.

  2. Create a Hugo site.

  3. Open a command prompt at the root of the site and download the theme:

git init
git submodule add https://github.com/ldeso/hugo-flex.git themes/hugo-flex
  1. Add the theme to the site configuration. If the site configuration is a file called hugo.yaml:
echo 'theme: hugo-flex' >> hugo.yaml

Updating

Open a command prompt at the site's root directory and update the theme:

git submodule update --remote --rebase

Configuration

Any part of the default theme configuration can be copied to the site configuration to be modified. The default theme configuration is:

baseURL: https://example.org/
title: My New Hugo Site
languageCode: en-us
theme: hugo-flex

params:
  color: teal           # Any color in CSS syntax
  width: 42rem          # Any length in CSS syntax / leave empty to span page
  divider: \2500\2500   # Any string in CSS syntax / leave empty for no divider
  footer: >-            # HTML spaces ( ) are needed before HTML elements
    Except where otherwise noted, content on this site is licensed under a  
    <a href="http://creativecommons.org/licenses/by/4.0/" rel="license">Creative
    Commons Attribution 4.0 International License</a>.
  rss: To subscribe to this RSS feed, copy its address and paste it into your
    favorite feed reader.
  favicon: false        # Set to true to add a link to the favicon.ico
  noClasses: &nc false  # Set to true to use inline CSS for syntax highlighting
  katex: 0.16.10        # KaTeX version / leave empty to use the latest version
  headingoffset: 0      # Change heading levels when rendering markdown
  linkicons: false      # Set to hover or true to add a link icon to headings
  summaries: false      # Set to true to show summaries of posts on homepage
  schema: false         # Set to true to add Schema.org metadata
  opengraph: false      # Set to true to add Open Graph metadata
  twittercards: false   # Set to true to add Twitter Cards metadata
  utterances:
    repo:               # Set to Utterances repo URL to add Utterances comments
    issueterm:          # Leave empty for the default blog post to issue mapping
    theme:              # Leave empty to use the adaptive Utterances dark theme
  netlify:
    honeypot: false     # Set to true to add honeypot field in contact form
    recaptcha: false    # Set to true to add recaptcha challenge in contact form
  math: &math false     # Set to true to render LaTeX without using shortcodes
  mathdelim: &md
    block:              # List of pairs of "display" math delimiters
      - ['\[', '\]']
      - ['$$', '$$']
    inline:             # List of pairs of inline math delimiters
      - ['\(', '\)']
  # css:                # Uncomment to add custom CSS from the assets directory
  #   - css/foo.css
  #   - bar.css
  # js:                 # Uncomment to add custom JS from the assets directory
  #   - js/foo.js
  #   - bar.js

markup:
  highlight:
    noClasses: *nc      # Set to same value as params.noClasses
  goldmark:
    extensions:
      passthrough:
        enable: *math   # Set to the same value as params.math
        delimiters: *md # Set to the same value as params.mathdelim

menu:
  main:
    - name: About
      pageRef: /about
      weight: 1
    - name: Posts
      pageRef: /post
      weight: 2
    - name: Tags
      pageRef: /tags
      weight: 3
    - name: Categories
      pageRef: /categories
      weight: 4
    - name: RSS
      pageRef: /
      weight: 5
      params:
        - format: rss

outputFormats:
  rss:
    mediatype: application/rss+xml
    baseName: feed      # Rename RSS feed URL from rss.xml to feed.xml

Built-In Shortcodes

Math Rendering

Mathematical formulas written in LaTeX notation can be rendered to HTML on the client side by bundling the KaTeX library with the website. Rendering can take place either globally, or in specific locations using a built-in shortcode.

  1. Math can be rendered globally or on a per-page basis by setting the math parameter to true in the site configuration or on specific pages, and by enabling the passthrough extension in the site configuration.

  2. If the math parameter is set to false, mathematical formulas can still by rendered by surrounding them with the math shortcode:

    {{% math %}}
    Inline formulas such as $y=ax+b$ are supported, displayed formulas as well:
    
    $$e^{i\pi}+1=0$$
    {{% /math %}}
    

As of 2024, it is not yet possible to render math on the server side with Hugo.

Netlify Contact Form

A contact form that works with the Netlify Forms service can be inserted with the shortcode:

{{< contact >}}

A custom URL for the success page may be given as a parameter:

{{< contact "/success" >}}

SoundCloud Player

A privacy-friendly SoundCloud player can be inserted with the shortcode:

{{< soundcloud https://soundcloud.com/artist/track >}}

The embed player will only load after user input, and will be replaced by a simple link if JavaScript is disabled.

Syntax Highlighting

By default, syntax highlighting in Hugo adds inline styles to the HTML code generated by the syntax highlighter. This can be problematic if the site has a strict Content Security Policy. This theme makes it possible to automatically use an external stylesheet for syntax highlighting.

To use an external style sheet instead of inline styles, switch the options markup.highlight.noClasses and params.noClasses to false in the site configuration. The resulting external style sheet is only included on pages of the site that require it.

The default syntax highlighting style is called github-dark. To use a different style, a style sheet can be generated at the location assets/css/syntax.css by running the following command at the site root:

hugo gen chromastyles --style style-name > assets/css/syntax.css

The styles featuring both a high contrast and good compatibility with dark mode are called average, doom-one, doom-one2, github-dark, modus-operandi (light background), modus-vivendi, rrt, and witchhazel.

Custom CSS and JS

This theme offers two ways to add custom CSS or JS assets, allowing minor modifications to be applied without needing to create a fork.

Site-Wide

Custom CSS and JS files can be loaded as part of the base assets linked by every page. To do so, their filenames have to be added to the site configuration:

params:
  css:
    - css/foo.css
    - bar.css
  js:
    - js/foo.js
    - bar.js

The paths are relative to the asset directory. In this example, the file paths relative to the site root would be: assets/css/foo.css, assets/bar.css, assets/js/foo.js, and assets/bar.js.

Dynamically Embedded

Sometimes, custom CSS or JS is needed only on specific pages. This theme offers a mechanism to load CSS or JS assets through shortcodes. The assets are loaded only once per page, even if they are required by several shortcodes in the same page.

To load a CSS or a JS resource on each page where a shortcode is used, the shortcode template has to add the resource to the css or the js key of the Scratch variable. For instance, a shortcode template myshortcode.html containing the line

{{ resources.Get "myscript.js" | fingerprint | .Page.Scratch.SetInMap "js" "myscript" }}

will cause myscript.js to be loaded on every page where myshortcode is used.

As a real-life example, this is the template for the built-in SoundCloud shortcode:

{{ resources.Get "css/soundcloud.css" | .Page.Scratch.SetInMap "css" "soundcloud" }}
{{ resources.Get "js/soundcloud.js" | .Page.Scratch.SetInMap "js" "soundcloud" }}

<div class="Soundcloud">
  <a href="{{ .Get 0 }}" target="_blank" class="Soundcloud-box Soundcloud-box--link"><span class="Soundcloud-ellipsis">{{ .Get 0 }}</span></a>
</div>

License

This theme is licensed under the Apache License 2.0.

hugo-flex's People

Contributors

gpanders avatar jasonc avatar ldeso avatar puhoy avatar scivision avatar xiahualiu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hugo-flex's Issues

blank index.xml renders

Ever since I started using hugo-flex several months ago, I noticed that any */index.xml yield a blank page or bare HTML code unprocessed.
It looks like maybe the code generating index.xml is not working as intended.
This becomes a real issue because search engines index and return high ranking results for these index.xml pages, which to users are blank or garbled.
My solution was to overload rss.xml that gave only the plain xml for machine use, which search engines recognize not to put into human search results.

patch for Hugo 0.57 rss.xml

This patch fixes index.xml not working correctly on Hugo 0.57

diff --git a/layouts/_default/rss.xml b/layouts/_default/rss.xml
index 1e93baa..4f28dac 100644
--- a/layouts/_default/rss.xml
+++ b/layouts/_default/rss.xml
@@ -10,7 +10,7 @@
     <webMaster>{{ . }}{{ with site.Author.name }} ({{ . }}){{ end }}</webMaster>{{ end }}{{ with site.Copyright }}
     <copyright>{{ . }}</copyright>{{ end }}{{ with .Date | default nil }}
     <lastBuildDate>{{ .Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}{{ with .OutputFormats.Get "RSS" }}
-    {{ printf `<atom:link href=%q rel="self" type=%q />` .Permalink .MediaType | safeHTML }}{{ end }}{{ range where .Pages "Type" "in" site.Params.mainSections }}
+    {{ printf `<atom:link href=%q rel="self" type=%q />` .Permalink .MediaType | safeHTML }}{{ end }}{{ range where site.RegularPages "Type" "in" site.Params.mainSections }}
     <item>
       <title>{{ .Title }}</title>
       <link>{{ .Permalink }}</link>

possible speed regression with Hugo 0.65.x

This hugo-flex template has worked well for several Hugo 0.5x and through 0.64 very fast.

Upon using Hugo 0.65.x, my ~2000 page scivision.dev site builds 4x slower. Through 0.64.x, my site built in about 6 seconds. Using Hugo 0.65.x my site builds in 26 seconds.

This could possibly have to do with the new approaches to taxonomies etc. in 0.65 https://github.com/gohugoio/hugo/releases/tag/v0.65.0

Hugo is still vastly faster than Jekyll, but just something to think about, if it's something in Hugo vs. hugo-flex causing this apparent slowdown.

How to avoid margins?

It seems that 'Hugo Flex' is excellent for my purposes.

If I view the demo on a smartphone I get this (1920x1080):

Screenshot_20190414-112717_Chrome

... and on a tablet (or desktop) that (2560x1600):

Screenshot_2019-04-14-11-27-44

Question: How is it possible to avoid the empty margins on a tablet or desktop?

Or in other words: How can the full width of the screen be used for content?

Soundcloud Playback

How exactly do i embed a soundcloud track to my hugo site?

I tried using the shortcode as suggested {{< soundcloud 123456789 >}} into the content of the markdown, but nothing shows up.

Do i have to modify the soundcloud.html file at all or leave it as is?

I have seen a number of hugo shortcodes for soundcloud, but nobody has given an actual practical example. Its all theoretical.

Do you have an Example Site?

I am interested in creating a site, but there is no "Example Site" in your theme. Do you have a sample? I can build one up but thought I'd ask first.

Menus

Use url to configure external links and pageRef to configure internal links in the menu. I saw you using the former.

Tags and Categories pages

I have added a post and an About page. However the Tags and Categories pages are not generated. How do I get them to be generated?

utterances not working

for some reason, the $.Type variable is empty in comments.html.
if i move the whole condition ( {{ if in site.Params.mainSections $.Type | and site.Params.utterances.enable }} ) from comments.html to single.html, it works.

also, "enable" should be "enabled" to match with the readme.

hugo-flex with dark mode

Would you be interested in adding a dark mode version of your theme?

There are some tips here for example. To keep hugo-flex simple, I would not apply tip 7 (I guess a toggle or a let the system decide would require some js?) and just set the theme -light or dark- with a dedicated entry in the Hugo config file.

provide css through script instead of inline

Hello!

thanks for providing this nice template I am relly liking it!
Unfortunately this template has CSS inline in the HTML, which conflicts with usual CSP configuration .

A temporary workaround is to put the CSP header with

style-src 'self' 'unsafe-inline'

however, as the name suggest this is unsafe as it might open the website to attacks if later someone has a sub directory where users can write something. To avoid this it would be awesome if you could provide the css through a file instead of loading it inline; do you think this is possible ?

Can’t mix math and Markdown in the same paragraph

It seems that it’s currently not possible to mix Markdown and inline math in the same paragraph:

  • {{<math>}}Here is [a link](https://github.com/ldeso/hugo-flex). By the way, $1 + 1 = 2$.{{</math>}}
    

    would cause the link not to be rendered.

    (Replacing this line:

    with {{ .Inner | markdownify }} would solve this, and would let one just wrap an entire article in {{<math>}}.)

  • Here is [a link](https://github.com/ldeso/hugo-flex). By the way, {{<math>}}$1 + 1 = 2${{</math>}}.
    

    renders the link and the math but the math is displayed in its own block since it gets put in a <div>. (And having to intersperse an entire article with these would not be ideal.)

Or perhaps I am missing something?

Thanks.

Language code

In your baseof.html

<html{{ with site.LanguageCode | default site.Language.Lang }} lang="{{ . }}"{{ end }}>

Could work better if replaced with this instead

<html lang="{{ or site.LanguageCode site.Language.Lang }}">

which is the standard way to define the language code in Hugo.

patch to add metadata using Hugo internals

This patch does two things:

  1. puts canonical link in the header. this is useful for sites that do redirects so that they don't get penalized by search engines for duplicated content.
  2. adds auto-generated metadata to header from Hugo internals: https://github.com/gohugoio/hugo/tree/master/tpl/tplimpl/embedded/templates
--- layouts/_default/baseof.html       2019-08-16 01:01:55.636909100 -0400
+++ layouts/_default/baseof.html        2019-08-16 01:31:07.890929500 -0400
@@ -6,6 +6,12 @@
 <head>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <link rel="canonical" href="{{ .Site.BaseURL }}{{ .RelPermalink }}">
+
+  {{ template "_internal/schema.html" . }}
+  {{ template "_internal/opengraph.html" . }}
+  {{ template "_internal/twitter_cards.html" . }}
+
   <title>
     {{ if eq .Title site.Title }}
     {{ site.Title }}

showing page categories as well as tags

I like to list category as well as tag for each page. Does this seem like a reasonable options? Here's how I've been overloading this functionality:

I insert into my layouts/_default/single.html and layouts/index.html the line

{{ partial "categories.html" . }}

referring to layouts/partials/categories.html containing

{{ with .Params.categories }}
<footer>
  <ul class="Tags">
    {{ range . }}
    {{ $name := . }}
    {{ with $name | urlize | printf "/categories/%s" | site.GetPage }}
    <li class="Tags-item u-background">
      <a class="Tags-link u-clickable" href="{{ .Permalink }}" rel="category">{{ $name }}</a>
    </li>
    {{ end }}
    {{ end }}
  </ul>
</footer>
{{ end }}

Custom css not working as expected

Hi, first of all, thanks for providing this theme!
I tried customizing my page a bit with an external css file like shown in the README, but I can't get it to load.

I created a style file static/css/foo.css, containing some syle instructions.
In config.yaml, I added

css:
  - css/foo.css

When building the page, the foo.css file shows up in the correct place in the public folder. But there is no reference to it anywhere. Am I doing something wrong in my config file or is this a bug in the theme?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.