Skip to content

DenysPacheco/css-hash-convert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Css Hashfy & Minify Converter ♻️

Hashfier Banner

This is a Python script to hashfy & minify css classes and html tags.

It was inspired on Google's approach to minimize class names for faster loading web pages and a bit of my ideas.

(Plus a few things that I would like to see together on the same place)

Contents

😄 What it does

  • Make a random hash each run out of css and id classes (see overwrite)
  • Minify css and html files
  • Remove comments 👌
  • Create .min suffixed files as output
  • Auto apply changes for all the html files (class subst and style link tags)
  • Multiple files on multiple folders (top-down) ✨

📘 Usage

Just put these files on the most top folder and execute.

Alternatively...

You can run the python script and pass as args the source folder for the conversion.

python convert.py ./templates/

It will search for all the files with the matching extensions in the sub-folders marked on the configuration file and do the changes. (default .html and .css)

It will give the output with foo.min.html and foo.min.css on the same directories as the original ones.

📄 Documentation

Also, if you want to see the functions or read the code (more hardcore 🤨) used on this project, please check the documentation page.

⚙️ Configure

Change in the configuration file the directories to be ignored, hash length, overwrite files and others. (On the convert.min.py the configurations are in the beginning of the file)

Configuration options

Flags Description
filesSearch Extensions of the files to search
filesIgnore Extensions of the files to ignore
dirsSearch Directories to do the search
dirsIgnore Directories to ignore on the search
suffix Suffix of the output files
prefix Prefix of the css classes
patternCSS Regex of the css to take classes and ids
patternHTML Regex of the html to take the classes
patternCSSClear Regex to remove the css comments
patternHTMLClear Regex to remove the html comments
patternHTMLLinks Regex to remove the html link
patternHTMLLinksAlt Alternative Regex to remove the html links
patternHTMLHead Regex to find the html head tag
hashLength Length of the hash
overwriteFiles Overwrite the output files
minimize Minimize the files
console Print console output

overwrite note

Mind that: if overwrite: false, the css hash will not be equal to the old html files; > therefore: not in sync; > therefore: 👋 bye bye css.

🤔 What to come

  • How about js too?
  • Obfuscate everything?