- #SIMPLEIMAGE CREATOR GENERATOR#
- #SIMPLEIMAGE CREATOR UPDATE#
- #SIMPLEIMAGE CREATOR FULL#
- #SIMPLEIMAGE CREATOR CODE#
If not os.path.exists(folders + '/optimised'): If os.path.exists(folders + '/optimised'): # If the path exists, delete it (and contents) to start afresh # Managing subdirectories for image optimizations: #dirs = sorted(os.listdir()) # This will get all of the files and subdirectories in a folderįolders_string = folders.replace (' ', r'\ ') # This ensures that when we call a subprocess, the filepath is correctly passed for terminal. The optimizations are handled by the optimizations.py file: #!/usr/bin/env python3ĭirs = sorted(next(os.walk('.'))) # This will get all of the subdirectories in a folder TBH, I should be optimizing the homepage images too, but I started with the assumption that the hompage would be handled separately from everything else. Once the homepage is built, I move on to optimizing all of the images in the subdirectories.
#SIMPLEIMAGE CREATOR UPDATE#
If you want to manually create a homepage with images and copy without autogenerating it like this, feel free to disregard this entire file – just delete it from the process, and update the /snippets/5-body-images.html manually. The end result is an html file that might look something like this: Then, for each loop, I append that to a clean.
#SIMPLEIMAGE CREATOR CODE#
For each image, I run them through a loop at add some code to them.Then reading the directory for a predefined list of supported image types.Defining a few functions and variables (particularly startImg and endImg which are html wrappers I want to add before and after each image file to get them to show up in html.I might go back and clean up the functions at some point, but the logic is: I wrote this early on as a bit of copypasta when I was trying to figure out how Python works. # It reads each file and reads the content to the writeFile, then adds a line break ("\n") If file.endswith(tuple(img_list)): # Reading only image files WriteFile= open("./snippets/5-body-images.html","w+") This builds the "homepage" list of images: #!/usr/bin/env python3 Step 7: Go back to the index and run open.py to open to website when it has compiled. Step 4: Run the buildImagelist-withsubdirectoy.py code You only need to do this once.Īnyway, let's take it section by section: I also like leaving tooltips for the build process so I can see if the code gets hung up somewhere.Īlso – if you're running this for the first time, you'll need to adjust your permissions to execute the file by running chmod +x Build.sh and pressing enter. Note, I added a lot of comments in my code to keep it clear and readable. Printf "\033[0 32m All good! Launching site. # Just a tooltip to let you know the script is running. # Go back and launch the page locally for testing # Combine various html snippets into one core index.html file
Python3 buildImageList-withsubdirectory.py # Read the images directory and wrap the images in HTML
#SIMPLEIMAGE CREATOR FULL#
This runs in the terminal and executes a sequence of python scripts that go through your folders, optimize the images, and then writes HTML snippets that are compiled into a full website at the end. The code runs via a shell script named Build.sh.
#SIMPLEIMAGE CREATOR GENERATOR#
I recently built a static site generator that scratched quite a few itches for me, not least of all being 'learning python'.