xonecas.io
117
Ht

htmlKompressor / commit f4f9bd3

first!

xonecas2011-06-02 f4f9bd30eac028adf9a1d159d29154d204e54e43

4 files changed

README.md+1−0
@@ -0,0 +1 @@
1+# See source `:-)`
index.html+67−0
@@ -0,0 +1,67 @@
1+<!doctype html><!--[if lt IE 9 ]> <html class="no-js oldie" lang="en"> <![endif]--><!--[if (gte IE 9)|!(IE)]><!--> <html class="no-js" lang="en"> <!--<![endif]--><head><meta charset="utf-8"><title>Dusty Markdown</title><meta name="description" content="simple command line content manager"><meta name="author" content="@xonecas"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="shortcut icon" href="/favicon.ico"><link rel="apple-touch-icon" href="/apple-touch-icon.pn …
2+ <p>This project is the new content manager under <a href="http://xonecas.com">xonecas.com</a>.
3+ It's very minimal and light, developer friendly. The idea
4+ is that you can write the dynamic content in markdown and
5+ use dust to combine static and dynamic.</p>
6+</blockquote>
7+
8+<h2>This app is only possible thanks to:</h2>
9+
10+<ul>
11+<li>HTML5 Boilerplate</li>
12+<li>Dust.js</li>
13+<li>Markdown</li>
14+</ul>
15+
16+<h3>The gist:</h3>
17+
18+<p>So the build.js file grabs the source files you write and
19+compiles them into static assets (@TODO add compression
20+and concatenation). The way it knows what to do with your
21+files is because it expects a specific folder/naming
22+convention.</p>
23+
24+<p>This app is the example of that convention:</p>
25+
26+<pre><code> root/
27+ build.js // compiler
28+ server.js // static asset provider
29+
30+ templates/ // home to your pages/views
31+ index.dust // root of the app
32+ pagename.dust // pagename becomes
33+ // http://server/pagename
34+
35+ markdown/ // where your content goes
36+ keyname.md // you can refer to this in
37+ // your template using {keyname}
38+ section_keyname.md // you can refer to several
39+ // keynames using {#section}
40+ htdocs/ // your static content
41+ ...
42+ ... // organize it how you want it
43+ // just remember that the .html
44+ // files are created by build.js
45+ // so don't edit them by hand
46+</code></pre>
47+
48+<p>The default htdocs folder is from HTML5 Boilerplate and so is
49+the static file server. One difference is that this app uses
50+Ender for the js library, but you're welcome to change it.
51+There is also a very simple unique visitors/request counter.</p>
52+
53+<p>See the example page <a href="/about">here</a>.</p>
54+
55+<h2>Dependencies</h2>
56+
57+<ul>
58+<li><code>npm install connect dust node-markdown</code></li>
59+</ul>
60+
61+<h2>More docs:</h2>
62+
63+<ul>
64+<li><a href="http://h5bp.com/"><em>HTML5 Boilerplate</em> →</a></li>
65+<li><a href="http://akdubya.github.com/dustjs/"><em>Dust</em> →</a></li>
66+<li><a href="http://daringfireball.net/projects/markdown/basics"><em>Markdown</em> →</a></li>
67+</ul></section><script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js"></script><script>window.jQuery || document.write("<script src='js/libs/jquery-1.5.1.min.js'>\x3C/script>")</script><!-- scripts concatenated and minified via ant build script--><script src="js/plugins.js"></script><script src="js/script.js"></script><!-- end scripts--><!--[if lt IE 7 ]><script src="js/libs/dd_belatedpng.js"></script><script>DD_belatedPNG.fix("img, .png_bg");</script><![endif]--></body></html>
lib/kompressor.js+43−0
@@ -0,0 +1,43 @@
1+// by @xonecas based on https://github.com/tylerhall/html-compressor.git
2+module.exports = function (source, noComments) {
3+ var lines = source.split("\n"),
4+ insidePre = false, kompressed = "";
5+
6+ while (lines.length > 0) {
7+ var line = lines.shift();
8+
9+ if (!insidePre) {
10+ var start = line.match(/\<pre/);
11+ if (start) {
12+ line.replace(/^\s+/, ""); // only before the pre tag
13+
14+ // does it end in the same line?
15+ var end = line.match(/\<\/pre\>/);
16+ if (end && end.index > start.index)
17+ line.replace(/\s+$/, "");
18+ else
19+ insidePre = true;
20+ }
21+ else { // no pre
22+ line.trim();
23+ line.replace(/\s\s+/, " "); // condense spaces
24+ }
25+ }
26+ else { // inside pre tag
27+ var end = line.match(/\<\/pre\>/);
28+ if (end) {
29+ line.replace(/\s+$/, "");
30+ insidePre = false;
31+ }
32+ }
33+
34+ kompressed += (insidePre)? line+"\n": line;
35+ } // end while
36+
37+ if (noComments) { // remove comments
38+ kompressed = kompressed.replace(/<\!--.*?--\>/g, "");
39+ }
40+
41+ return kompressed;
42+}
43+
test.js+8−0
@@ -0,0 +1,8 @@
1+var kompressor = require("./lib/kompressor.js"),
2+ fs = require('fs');
3+
4+fs.readFile("./index.html", "utf8", function (err, file) {
5+ if (err) throw err;
6+
7+ console.log(kompressor(file, true));
8+});