Forráskód Böngészése

Modifications on YUICompressor plugin

Issue: #
auroredea 8 éve
szülő
commit
186aa651bd

+ 0 - 3
.gitmodules

@@ -121,9 +121,6 @@
 [submodule "mboxreader"]
 	path = pelican-mboxreader
 	url = https://github.com/TC01/pelican-mboxreader
-[submodule "pelican-yuicompressor"]
-	path = pelican-yuicompressor
-	url = https://github.com/auroredea/pelican-yuicompressor
 [submodule "bootstrap-rst"]
 	path = bootstrap-rst
 	url = https://github.com/Alexqw/bootstrap-rst

+ 2 - 2
Readme.rst

@@ -190,8 +190,6 @@ Pelican Vimeo             Enables you to embed Vimeo videos in your pages and ar
 
 Pelican YouTube           Enables you to embed YouTube videos in your pages and articles
 
-Pelican Yuicompressor     Minify CSS and JS files on building step
-
 pelicanfly                Lets you type things like ``i ♥ :fa-coffee:`` in your Markdown documents and have it come out as little Font Awesome icons in the browser
 
 Photos                    Add a photo or a gallery of photos to an article, or include photos in the body text. Resize photos as needed.
@@ -255,6 +253,8 @@ txt2tags_reader           Reader that renders txt2tags markup in content
 Video Privacy Enhancer    Increases user privacy by stopping YouTube, Google, et al from placing cookies via embedded video
 
 W3C validate              Submits generated HTML content to the W3C Markup Validation Service
+
+Yuicompressor             Minify CSS and JS files on building step
 ========================  ===========================================================
 
 __ https://ace.c9.io

+ 0 - 1
pelican-yuicompressor

@@ -1 +0,0 @@
-Subproject commit 45f8e645f5d909da98f131923f9c53bf8dd8b6f0

+ 1 - 0
yuicompressor/.gitignore

@@ -0,0 +1 @@
+*.pyc

+ 19 - 0
yuicompressor/README.md

@@ -0,0 +1,19 @@
+# YUI Compressor Plugin
+
+A pelican plugin which minify through yui compressor CSS/JS file on building step.
+
+# Installation
+
+In order to work, JRE should be already installed.
+Please add `pip install yuicompressor`
+
+More info : (https://github.com/yui/yuicompressor)
+
+# Instructions
+
+Add `yuicompressor` to `pelicanconf.py` after install :
+`PLUGINS = ['yuicompressor']`
+
+# Licence
+
+GNU AFFERO GENERAL PUBLIC LICENSE Version 3

+ 2 - 0
yuicompressor/__init__.py

@@ -0,0 +1,2 @@
+# -*- coding: utf-8 -*-
+from .yuicompressor import *

+ 34 - 0
yuicompressor/yuicompressor.py

@@ -0,0 +1,34 @@
+# -*- coding: utf-8 -*-
+
+from pelican import signals
+from subprocess import call
+import logging
+import os
+
+logger = logging.getLogger(__name__)
+
+# Display command output on DEBUG and TRACE
+SHOW_OUTPUT = logger.getEffectiveLevel() <= logging.DEBUG
+
+"""
+Minify CSS and JS files in output path
+with Yuicompressor from Yahoo
+Required : pip install yuicompressor
+"""
+
+def minify(pelican):
+    """
+      Minify CSS and JS with YUI Compressor
+      :param pelican: The Pelican instance
+    """
+    for dirpath, _, filenames in os.walk(pelican.settings['OUTPUT_PATH']):
+        for name in filenames:
+            if os.path.splitext(name)[1] in ('.css','.js'):
+                filepath = os.path.join(dirpath, name)
+                logger.info('minifiy %s', filepath)
+                verbose = '-v' if SHOW_OUTPUT else ''
+                call("yuicompressor {} --charset utf-8 {} -o {}".format(
+                    verbose, filepath, filepath), shell=True)
+
+def register():
+    signals.finalized.connect(minify)