Code Monkey home page Code Monkey logo

lazysites's Introduction

lazysites

Transforms images of a static site into responsive lazy-loading images thanks to lazysizes.

Python script that traverses all HTML files of a directory and adds the lazyload class to each HTML img element as required by lazysizes, e.g. transforms this:

<img class="mt-3" src="foo.jpg" />

into

<img class="mt-3 lazyload" data-src="foo.jpg" />

for all HTML files.

It is specially designed to be run after a static website generator produces website's files. This way, you can use plain Markdown in them and just modify the resulting website without interfering with the generator so it can be applied to Hugo, Jekyll, etc.

How it works

  1. Starting in a directory, visits all its directories and subdirectories.

  2. Visits all .html files

  3. Checks for img tags and

    1. add lazyload class
    2. transforms src attribute to data-src
  4. Adds the JS library if not present any lazysizes.js:

     <script src="https://cdn.jsdelivr.net/npm/[email protected]/lazysizes.min.js"></script>
    

How to use it

Create a virtual environment

python3 -m venv ~/.virtualenvs/lazysite

Use it source ~/.virtualenvs/lazysite/bin/activate.

Install dependencies pip install -r requirements.txt

Copy your website files to ./public.

And run the generator python3 generator.py.

License

MIT licensed.

lazysites's People

Contributors

marcanuy avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.