hithismani / hugon

A script that simplifies working with archetypes in Hugo! (@gohugoio) Also supports bulk file creation/editing via a single .csv! 🐍
https://pypi.org/project/hugon/
MIT License
17 stars 1 forks source link
hugo python python-3 python3

======================= hugon (Hugo + Python)

.. image:: https://raw.githubusercontent.com/hithismani/hugon/master/sample/header.jpg :alt: Hugon Header Image

.. image:: https://img.shields.io/pypi/v/hugon.svg :target: https://pypi.python.org/pypi/hugon

An incredibly simple (CLI) python script that makes working with archetypes in Hugo 0.5x much easier. Also automates the process of bulk file creation via a single .csv!

Read my medium post_ for a quick idea of what this package does.

.. _my medium post: https://medium.com/@helloitsmani/trying-to-speed-up-your-hugo-workflow-with-python-try-hugon-13e81cc32571

.. image:: https://raw.githubusercontent.com/hithismani/hugon/master/sample/hugon-single-file.gif :alt: Hugon Sample Run

Why

Features

Requirements

How To Use (Normal)

  1. Install Hugon::

    pip install hugon

2) cd Into your hugo project folder. 3) run the command::

hugon -name "N3w F!le" -archetype "default" -sequence "5"

Syntax (Normal)

+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------+-------------------+------------------------------------------------+ | Command | Description | Required? | Example | Converts Into | +------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------+-------------------+------------------------------------------------+ | -archetype | Define Archetype Name (without file extension). The Archetype file of this name should be present in the archetype folder. (Name is automatically converted to lowercase) | Yes | Default | default | +------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------+-------------------+------------------------------------------------+ | -name | Filename you'd want to set. Can contain spaces, numbers, special characters, all which will be stripped (and converted to lowercase) to create a seamless file name to send to Hugo CLI. | Yes | FILE NAM3 Ex@mple | file-nam3-exmple.md | +------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------+-------------------+------------------------------------------------+ | -sequence | Lets you create multiple files with a 'sequence' as a postfix. Helpful if you're working with FAQ's, or other pages where file name doesn't necessarily matter. Value has to be more than 1, with sequence kicking off skipping 0.| No | 5 | file-nam3-exmple1.md | | | | | +------------------------------------------------+ | | | | | file-nam3-exmple2.md | | | | | +------------------------------------------------+ | | | | | file-nam3-exmple3.md | | | | | +------------------------------------------------+ | | | | | file-nam3-exmple4.md | | | | | +------------------------------------------------+ | | | | | file-nam3-exmple5.md | +------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------+-------------------+------------------------------------------------+ | -separator | Lets you define a custom separator that's not "-" a hyphen. | No | _ | file_nam3_example.md | +------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------+-------------------+------------------------------------------------+ | -prefix | Use another command instead of "hugo new". | No | npm run customdev | npm run customdev default/file_nam3_example.md | +------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------+-------------------+------------------------------------------------+

How To Use (Generate From CSV)

1) Create a 'data.csv' file in the root of your hugo site. 2) Enter all the required variable fields (along with the required compulsory fields) as columns on your first row, and populate to your hearts content. 3) Run command::

hugon -csv yes

4) If you'd like to overwrite your files without being prompted (Risky) just pass '-overwrite true' as an argument.::

hugon -csv yes -overwrite true

Syntax (CSV)

.. image:: https://raw.githubusercontent.com/hithismani/hugon/master/sample/hugon-csv.gif :alt: Hugon Sample Run | CSV

Warning: Files would be modified the moment they're made. Mistakes cannot be undone.

+-------------+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Column Name | Required | Purpose | +-------------+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | archetype | Yes | States archetype of post to be made. | +-------------+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | content | No | Lets you add matter to the "content" section of your markdown file. | +-------------+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | filename | No | Lets you specify another filename if you don't want to use a 'sluggified' title. Please ensure you don't add '.md' to the filename and your file name has the proper separators. | +-------------+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | title | Yes | Title field/filename. | +-------------+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | da- | No | Download Anchorlink column that lets the script know that the value of the field is a download link. Must be followed by the key it assigns to. Eg: 'da-image'. Single use only. | +-------------+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | path | No(?) | (Required if 'da-' is specified) Lets the script set the download location of the file specified above. Creates the folder if it doesn't exist. | +-------------+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | prefix | No | Any custom build command you'd like to specify. | +-------------+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | separator | No | Any custom separator (if you're generating from title column) apart from default '-'. | +-------------+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

.. _sample CSV attached within this repository: https://github.com/hithismani/hugon/blob/master/sample/data.csv

TO DO

Credits


.. Cookiecutter: https://github.com/audreyr/cookiecutter .. audreyr/cookiecutter-pypackage: https://github.com/audreyr/cookiecutter-pypackage