NewsBlur/utils/pipeline_utils.py

118 lines
2.9 KiB
Python
Raw Normal View History

import re
from django.conf import settings
from pipeline.finders import FileSystemFinder as PipelineFileSystemFinder
from pipeline.finders import AppDirectoriesFinder as PipelineAppDirectoriesFinder
from pipeline.storage import GZIPMixin
from pipeline.storage import PipelineManifestStorage
2024-04-24 09:43:56 -04:00
class PipelineStorage(PipelineManifestStorage):
def url(self, *args, **kwargs):
if settings.DEBUG_ASSETS:
# print(f"Pre-Pipeline storage: {args} {kwargs}")
2024-04-24 09:43:56 -04:00
kwargs["name"] = re.sub(r"\.[a-f0-9]{12}\.(css|js)$", r".\1", args[0])
args = args[1:]
url = super().url(*args, **kwargs)
if settings.DEBUG_ASSETS:
url = url.replace(settings.STATIC_URL, settings.MEDIA_URL)
2024-04-24 09:43:56 -04:00
url = re.sub(r"\.[a-f0-9]{12}\.(css|js)$", r".\1", url)
# print(f"Pipeline storage: {args} {kwargs} {url}")
return url
2024-04-24 09:43:56 -04:00
class GzipPipelineStorage(GZIPMixin, PipelineManifestStorage):
pass
2024-04-24 09:43:56 -04:00
class AppDirectoriesFinder(PipelineAppDirectoriesFinder):
"""
Like AppDirectoriesFinder, but doesn't return any additional ignored patterns
This allows us to concentrate/compress our components without dragging
the raw versions in too.
"""
2024-04-24 09:43:56 -04:00
ignore_patterns = [
# '*.js',
# '*.css',
2024-04-24 09:43:56 -04:00
"*.less",
"*.scss",
"*.styl",
"*.sh",
"*.html",
"*.ttf",
"*.md",
"*.markdown",
"*.php",
"*.txt",
# '*.gif', # due to django_extensions/css/jquery.autocomplete.css: django_extensions/img/indicator.gif
2024-04-24 09:43:56 -04:00
"*.png",
"*.jpg",
# '*.svg', # due to admin/css/base.css: admin/img/sorting-icons.svg
2024-04-24 09:43:56 -04:00
"*.ico",
"*.icns",
"*.psd",
"*.ai",
"*.sketch",
"*.emf",
"*.eps",
"*.pdf",
"*.xml",
"*LICENSE*",
"*README*",
]
2024-04-24 09:43:56 -04:00
class FileSystemFinder(PipelineFileSystemFinder):
"""
Like FileSystemFinder, but doesn't return any additional ignored patterns
This allows us to concentrate/compress our components without dragging
the raw versions in too.
"""
2024-04-24 09:43:56 -04:00
ignore_patterns = [
# '*.js',
# '*.css',
# '*.less',
# '*.scss',
# '*.styl',
2024-04-24 09:43:56 -04:00
"*.sh",
"*.html",
"*.ttf",
"*.md",
"*.markdown",
"*.php",
"*.txt",
"*.gif",
"*.png",
"*.jpg",
"*media/**/*.svg",
"*.ico",
"*.icns",
"*.psd",
"*.ai",
"*.sketch",
"*.emf",
"*.eps",
"*.pdf",
"*.xml",
"*embed*",
"blog*",
# # '*bookmarklet*',
# # '*circular*',
# # '*embed*',
2024-04-24 09:43:56 -04:00
"*css/mobile*",
"*extensions*",
"fonts/*/*.css",
"*flash*",
# '*jquery-ui*',
# 'mobile*',
2024-04-24 09:43:56 -04:00
"*safari*",
# # '*social*',
# # '*vendor*',
# 'Makefile*',
# 'Gemfile*',
2024-04-24 09:43:56 -04:00
"node_modules",
]