frankV / twenty-pelican-html5up

This is an adaptation of the html5up template "Twenty" for the Python static site generator Pelican.
Other
116 stars 43 forks source link

skel.js `collectstatic` addition for users of Python3+ #8

Closed errbufferoverfl closed 5 years ago

errbufferoverfl commented 6 years ago

Hi Frank,

While trying to roll out this theme I ran into a problem re: collectstatic as I am running Python3+. Pelican uses Fabric<2.0 to generate their fabfiles, here is a link to the closed issue which is not Python3 compatible.

As in the comment thread they have fixed this issue for Pelican 3.8. Until that is released, I didn't see much point in downgrading to Python2 so I quickly rolled a script to collect the static resources and move them over to the output directory, shown below.

#!/usr/bin/env python3
import shutil
from distutils.dir_util import copy_tree
import os

import pelicanconf

ROOT_DIR = os.path.dirname(os.path.abspath(__file__))

try:
    output_path = pelicanconf.OUTPUT_PATH
except (KeyError, AttributeError):
    output_path = ROOT_DIR + "/output/"

copy_tree(f"{ROOT_DIR}/{pelicanconf.THEME_STATIC_DIR}/{pelicanconf.THEME}/static/css/", f"{output_path}css/")
copy_tree(f"{ROOT_DIR}/{pelicanconf.THEME_STATIC_DIR}/{pelicanconf.THEME}/static/js/", f"{output_path}js/")
copy_tree(f"{ROOT_DIR}/{pelicanconf.THEME_STATIC_DIR}/{pelicanconf.THEME}/static/fonts/", f"{output_path}fonts/")
copy_tree(f"{ROOT_DIR}/{pelicanconf.THEME_STATIC_DIR}/{pelicanconf.THEME}/static/images/", f"{output_path}images/")

try:
    shutil.rmtree(f"{output_path}theme/")
except FileNotFoundError:
    pass

It's not perfect, but I thought I would share it here in case any other Python3+ users encounter a similar problem.

I haven't quite worked out a good place to hook it into my build process because I can't use the fabfile so I just run it manually for now.

I have updated the example included to remove the theme static resources directory in the output directory to make cleanup easier. I've also made this snippet into a gist.

frankV commented 5 years ago

Thanks @errbufferoverfl! I'm going to mark this closed but tag it so others can find it easily.