Giter VIP home page Giter VIP logo

jekyll-press's Introduction

jekyll-press

Minifier plugin for jekyll. Minifies all html, js, css files. Simple just drop it in solution. No Java required.

This plugin:

  • compress html with the help of html_press
  • compress JavaScript files with the help of uglifier
  • compress css files with the help of css_press

Alternative

Gulp based workflow see: sondr3/generator-jekyllized

Installation

Bundler

Add this line to your application's Gemfile:

gem 'jekyll-press'

And then execute:

$ bundle

Standalone

Execute:

$ gem install jekyll-press

Usage

With Bundler (recomended)

Create the following plugin in your projects _plugins directory.

# _plugins/bundler.rb
require "rubygems"
require "bundler/setup"
Bundler.require(:default)

This will automatically require all of the gems specified in your Gemfile.

Standalone

Create the following plugin in your projects _plugins directory.

# _plugins/jekyll-press-plugin.rb
require 'jekyll-press'

Settings

jekyll-press:
  exclude: 'atom.xml' # Exclude files from processing - file name, glob pattern or array of file names and glob patterns
  js_options: {}      # js minifier options
  css_options: {}     # css minifier options
  html_options: {}    # html minifier options

TODO

  • add test: run against simple jekyll site and check if there is no errors
  • Minify JPEGs with jpegtran or smush.it (smusher)
  • Minify PNGs with optipng or smush.it (smusher)
  • Auto CSS sprites (for example sprite factory)

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

jekyll-press's People

Contributors

stereobooster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jekyll-press's Issues

Not having much luck getting this to work

My folder structure is thus:

  • root
    • _layouts
      • default.html
    • _plugins
    • assets
      • css
        • styles.css
      • js
      • img
    • index.html
    • _config.yml

Index.html contains nothing excepf for defintion to use default.html as the layout. Default.html contains all the HTML including

<link href="assets/css/styles.css" rel="stylesheet" />

Although the HTML is compressed, the CSS doesn't seem to be touched. It feels like i'm missing something incredibly simple. Any ideas?

Althou


On another note altogether, it would be nice if you included some YAML to allow configuration of the compressors. For example I don't particularly want the HTML compressed, although I do want the CSS compressed. How does one toggle the individual features?

uninitialized class variable @@mtimes in Jekyll::StaticFile

Jekyll 3.2, Ruby 3.2.1.

bundler: failed to load command: jekyll (/Users/ari/.rbenv/versions/2.3.1/bin/jekyll)
NameError: uninitialized class variable @@mtimes in Jekyll::StaticFile
Did you mean?  mtimes
               @mtimes
  /Users/ari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-press-0.2.1/lib/jekyll-press.rb:89:in `write'
  /Users/ari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.2.0/lib/jekyll/site.rb:212:in `block in write'
  /Users/ari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.2.0/lib/jekyll/site.rb:333:in `block (2 levels) in each_site_file'
  /Users/ari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.2.0/lib/jekyll/site.rb:332:in `each'
  /Users/ari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.2.0/lib/jekyll/site.rb:332:in `block in each_site_file'
  /Users/ari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.2.0/lib/jekyll/site.rb:331:in `each'
  /Users/ari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.2.0/lib/jekyll/site.rb:331:in `each_site_file'
  /Users/ari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.2.0/lib/jekyll/site.rb:211:in `write'
  /Users/ari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.2.0/lib/jekyll/site.rb:71:in `process'
  /Users/ari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.2.0/lib/jekyll/command.rb:26:in `process_site'
  /Users/ari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.2.0/lib/jekyll/commands/build.rb:63:in `build'
  /Users/ari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.2.0/lib/jekyll/commands/build.rb:34:in `process'
  /Users/ari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.2.0/lib/jekyll/commands/build.rb:16:in `block (2 levels) in init_with_program'
  /Users/ari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
  /Users/ari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
  /Users/ari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
  /Users/ari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
  /Users/ari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
  /Users/ari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/jekyll-3.2.0/exe/jekyll:13:in `<top (required)>'
  /Users/ari/.rbenv/versions/2.3.1/bin/jekyll:23:in `load'
  /Users/ari/.rbenv/versions/2.3.1/bin/jekyll:23:in `<top (required)>'

Minification of xml_escape <code> content

I am using xml_escape to prepare my content for an RSS feed, but this means that when it is run through jekyll-press, new lines in code are minified and therefore lost.

For example:

&lt;pre&gt;&lt;code&gt;&amp;lt;div class=&quot;widget&quot;&amp;gt;…&amp;lt;/div&amp;gt;
&amp;lt;div class=&quot;widget&quot;&amp;gt;…&amp;lt;/div&amp;gt;
&amp;lt;div class=&quot;widget&quot;&amp;gt;…&amp;lt;/div&amp;gt;
&amp;lt;div class=&quot;widget&quot;&amp;gt;…&amp;lt;/div&amp;gt;
&amp;lt;!-- Exception --&amp;gt;
&amp;lt;div class=&quot;widget widget-secondary&quot;&amp;gt;…&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

Becomes:

&lt;/p&gt;&lt;pre&gt;&lt;code&gt;&amp;lt;div class="widget"&amp;gt;…&amp;lt;/div&amp;gt; &amp;lt;div class="widget"&amp;gt;…&amp;lt;/div&amp;gt; &amp;lt;div class="widget"&amp;gt;…&amp;lt;/div&amp;gt; &amp;lt;div class="widget"&amp;gt;…&amp;lt;/div&amp;gt; &amp;lt;!-- Exception --&amp;gt; &amp;lt;div class="widget widget-secondary"&amp;gt;…&amp;lt;/div&amp;gt; &lt;/code&gt;&lt;/pre&gt;

I think the only way to prevent this from happening is to prevent jekyll-press from minifying the file. Can you do that?

Environment variables

I have two versions of my project: on my local machine and on my production server. I would like Jekyll press to run on my production sever, but not when I am developing on my local machine.

How would this be achieved with jekyll_press?

P.S. you have duplicate repos: jekyll-press and jekyll_press.

Submodule

Thanks for the repo !

It would be great if jekyll_press.rb was in the root of the repo, so that we could use the repo as a git submodule.
Actually, it works as is, but then you have the path _plugins/jekyll_press/_plugins/jekyll_press.rb, which is awkward.

Here is the git command:

git submodule add git://github.com/stereobooster/jekyll_press.git _plugins/jekyll_press

(updates to be done via simple git pull inside the jekyll_press directory)

should be post processor not pre processor

There is a glitch here in the sequence of events that causes site text compression when used as-is.

If done properly then there is no need for ruby to cleanup the extra spaces but as-is, we are taking out potential br and paragraph codes as a preprocessor, when in post these would be just extra spaces in the html output. I have a ruby script that removes those and cleans up the html. It doesnt minify however.

--
desc "cleans up empty lines"
task :cleanup do
Dir['_site/**/*.html'].each do |file|
file_to_strip = IO.readlines(file)
fout = File.open("temp.html", "w")
in_code_block = false
file_to_strip.each do |line|
if line.include?("") or line.include?("

")
in_code_block = true
end
if (not in_code_block and not line.strip.empty?) or in_code_block
fout << line
end
if line.include?("
") or line.include?("
")
in_code_block = false
end
end
fout.close
File.rename("temp.html", file)
end
end

Error in HTML and in console

In the console I am getting this error from jekyll. This only occurs with jekyll_press:

parse error occurred while processing: /Users/Oliver/Development/Personal/OliverJAsh/site/css/base.css
details: parse error on value ":not(" (error)
copying initial file

I am also getting an error of Uncaught SyntaxError: Unexpected token ILLEGAL in the browser console. Something seems to be going wrong in the minification of the HTML here.

My project where I am witnessing this problems can be found here.

Doesn't compress posts html

If you have posts in folders such as
/recipes/_posts/post-name.md
(as is the new way of doing things)

It doesn't compress the html, but it does for /index.html and /recipes/index.html

Does not support CSS3 syntax

The plugin is unable to parse some CSS3 syntax.

For example, look at https://github.com/linuxtuts/linuxtuts.github.com

parse error occurred while processing: /_site/css/colors/transparent.css
details: parse error on value "$" ($end)
copying initial file
parse error occurred while processing: /_site/css/depend/fixstyles.css
details: parse error on value ":not(" (error)
copying initial file
parse error occurred while processing: /_site/css/mqs/print.css
details: parse error on value "^=" (error)
copying initial file
Successfully generated site: linuxtuts.github.com -> linuxtuts.github.com/_site

Not sure how to implement

Hey, I'm having trouble understanding the README. Just looking for clarification for what the contents of the actual .rb file should look like.

I chose the Standalone option..

Here's what I've done:

Installation: Fine. Easily installed the gem

Usage: You instruct to create the following:

# _plugins/jekyll-press-plugin.rb
require 'jekyll-press'

So I created a ruby file in my _plugins folder with the contents

require 'jekyll-press'

I was sure this wasn't correct, so I then tried to append the previous content with the settings as shown in the README:

jekyll-press:
exclude: 'atom.xml' # Exclude files from processing - file name, glob pattern or array of     file names and glob patterns
  js_options: {}      # js minifier options
  css_options: {}     # css minifier options
  html_options: {}    # html minifier options

Which led me to a .rb file with the following contents:

require 'jekyll-press'
jekyll-press:
exclude: 'atom.xml' # Exclude files from processing - file name, glob pattern or array of     file names and glob patterns
  js_options: {}      # js minifier options
  css_options: {}     # css minifier options
  html_options: {}    # html minifier options

I'm certain this isn't correct, but I'm not sure of what I need to do. Sorry to be a massive noob, but I can't seem to find answer anywhere else.

Java Exception when running jekyll build

Generating... Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.yahoo.platform.yui.compressor.Bootstrap.main(Bootstrap.java:21)
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at com.yahoo.platform.yui.compressor.JavaScriptCompressor.getToken(JavaScriptCompressor.java:578)
at com.yahoo.platform.yui.compressor.JavaScriptCompressor.printSymbolTree(JavaScriptCompressor.java:1094)
at com.yahoo.platform.yui.compressor.JavaScriptCompressor.compress(JavaScriptCompressor.java:556)
at com.yahoo.platform.yui.compressor.YUICompressor.main(YUICompressor.java:186)
... 5 more

State of the project: deprecated

When I started to use Jekyll it was the only one solution of that type. It was like a breath of fresh air. I like ideas behind it so much. It was a logical continuation of Markdown.

Historical info:

  1. There was markdown and Perl script to convert it to HTML
  2. Jekyll - which was able not just convert markdown, but website bundler. It is able to convert Markdown and provide everything, what is required. Front Matter deserves separate mention
  3. Next step will be JAM stack, but we not there yet. A lot of questions are unsolved

I keep using Jekyll, but only for the personal blog hosted on Github. But Github does not allow to use custom plugins like this one, so I do not see any sense to continue this work.

If you do not use Github as hosting give a try to modern alternatives.

If you still want to use Jekyll, try something like generator-jekyllized. Gulp is much better for this kind of tasks. It is faster (V8, JIT, streams, async IO). NodeJS has a ton of libs to handle frontend development: guetzli, AWS upload, UglifyJS, csso, critical and much much more.

So I do not see sense continue development of this project.

cannot load such file -- jekyll/post

This is what i get

› jekyll serve
Configuration file: /Users/niksmac/iWork/projects/blog/_config.yml
/Library/Ruby/Gems/2.0.0/gems/jekyll-press-0.2.1/lib/jekyll-press.rb:55:in `<module:Jekyll>': cannot load such file -- jekyll/post (LoadError)
    from /Library/Ruby/Gems/2.0.0/gems/jekyll-press-0.2.1/lib/jekyll-press.rb:7:in `<top (required)>'
    from /Users/niksmac/iWork/projects/blog/_plugins/jekyll-press-plugin.rb:1:in `require'
    from /Users/niksmac/iWork/projects/blog/_plugins/jekyll-press-plugin.rb:1:in `<top (required)>'
    from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.0.0/lib/jekyll/plugin_manager.rb:75:in `require'
    from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.0.0/lib/jekyll/plugin_manager.rb:75:in `block (2 levels) in require_plugin_files'
    from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.0.0/lib/jekyll/plugin_manager.rb:74:in `each'
    from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.0.0/lib/jekyll/plugin_manager.rb:74:in `block in require_plugin_files'
    from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.0.0/lib/jekyll/plugin_manager.rb:73:in `each'
    from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.0.0/lib/jekyll/plugin_manager.rb:73:in `require_plugin_files'
    from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.0.0/lib/jekyll/plugin_manager.rb:18:in `conscientious_require'
    from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.0.0/lib/jekyll/site.rb:97:in `setup'
    from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.0.0/lib/jekyll/site.rb:49:in `initialize'
    from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.0.0/lib/jekyll/commands/build.rb:30:in `new'
    from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.0.0/lib/jekyll/commands/build.rb:30:in `process'
    from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.0.0/lib/jekyll/commands/serve.rb:26:in `block (2 levels) in init_with_program'
    from /Library/Ruby/Gems/2.0.0/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `call'
    from /Library/Ruby/Gems/2.0.0/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `block in execute'
    from /Library/Ruby/Gems/2.0.0/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `each'
    from /Library/Ruby/Gems/2.0.0/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `execute'
    from /Library/Ruby/Gems/2.0.0/gems/mercenary-0.3.5/lib/mercenary/program.rb:42:in `go'
    from /Library/Ruby/Gems/2.0.0/gems/mercenary-0.3.5/lib/mercenary.rb:19:in `program'
    from /Library/Ruby/Gems/2.0.0/gems/jekyll-3.0.0/bin/jekyll:17:in `<top (required)>'
    from /usr/local/bin/jekyll:23:in `load'
    from /usr/local/bin/jekyll:23:in `<main>'

Is there documentation on the available options?

The README shows the following for the _config.yml file, but it's not clear to me what the possible options are.

jekyll-press:
  exclude: 'atom.xml' # Exclude files from processing - file name, glob pattern or array of file names and glob patterns
  js_options: {}      # js minifier options
  css_options: {}     # css minifier options
  html_options: {}    # html minifier options

Is this documented anywhere? I looked in the code and I couldn't see any places that made use of these. I checked the html_press repo, but it didn't have any documentation either.

Thanks.

What if your Website is not in English

Jekyll manage utf-8 character pretty well. Nevertheless, jekyll-press use gems that do not do as well. While I was running jekyll server I encountered the following error :

/home/jharvard/.gem/ruby/gems/json-1.8.1/lib/json/common.rb:223:in `encode': "\xE2" on US-ASCII (Encoding::InvalidByteSequenceError)

The way to fix it was for me to use : LANG="fr_FR.UTF-8" bundle exec jekyll serve instead.

is there a better way to fix that ?

PS : I still got an error on a css file but was the bootstrap file so I am guessing it has nothing to do with encoding this time.

Code in Markdown is being stripped of white space

If I write some code in a Markdown file and indent it by four spaces so it goes inside a pre element when converter, e.g.:

body {
  font-size: 16px;
}

p {
  color: gray;
}

Then what actually outputs is:

body {
  font-size: 16px;
}
p {
  color: gray;
}

Optimizing CSS and JS

Compressing and minifying is already effective, but I believe that this plugin can be made more effective through these ways:

  1. JSlim (https://github.com/zgrossbart/jslim) which can remove unused functions in JS
  2. Deadweight (https://github.com/aanand/deadweight) which can remove unused CSS. Not able to check JS files.
  3. Google Closure Compiler to optimize JS.
  4. Combine similar rules.

Here's what I mean by No. 4.

a {
    color: #000000;
}
p {
    background-color: #000000;
    color: #000000;
}

INTO

a, p {
    color: #000000;
}
p {
    background-color: #000000;
}

after minification to avoid problems with whitespace. It should only execute if minification suceeds. Which means the actual result would look like:

a,p{color:#000000;}p{background-color:#000000;}

jekyll_press doesn't work with Pygments

some symbols like <, >, & in highlight section, Test:

{% highlight bash %}
<This doesn't work.>
{% endhighlight %}

{% highlight bash %}
&This doesn't work, either.&
{% endhighlight %}

output:

%MINIFYHTML1347762883%1%This doesn't work.%MINIFYHTML1347762883%2%

%MINIFYHTML1347762883%3%This doesn't work, either.%MINIFYHTML1347762883%4%

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.