├── .gitignore
├── README.md
├── build
├── data.json
├── images
│ └── screenshot.png
├── index.html
├── scripts
│ ├── core.js
│ ├── core.js.map
│ ├── home.js
│ └── home.js.map
├── sitemap.xml
└── styles
│ ├── core.css
│ ├── core.css.map
│ ├── home.css
│ └── home.css.map
├── gulpfile.js
├── package.json
└── source
├── data
├── .gitkeep
└── index.js
├── images
├── .gitkeep
└── screenshot.png
├── scripts
├── .gitkeep
├── core.js
├── home.js
└── tools
│ └── log.js
├── statics
└── .gitkeep
├── styles
├── .gitkeep
├── core.less
├── home.less
└── tools
│ └── reset.less
└── templates
├── index.html
└── layouts
└── basic.html
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 |
3 | node_modules
4 | npm-debug.log
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Yet another front-end build process #
2 |
3 | THIS PROJECT IS DEPRECATED! TRY THIS INSTEAD: https://github.com/koljakutschera/laststaticsitegenerator
4 |
5 | Version: 1.2.4
6 |
7 | Simple but powerful static site generator, starter or boilerplate.
8 |
9 | Impression:
10 |
11 | 
12 |
13 | ## Features ##
14 |
15 | * Templating (Layouts, blocks, includes, macros, more)
16 | * Template data layer (Access data in template or via ajax: global, per page, from all pages)
17 | * Template helpers(moment.js, accounting.js)
18 | * Modular less-stylesheets (Hot-reloading)(Autoprefixed)(Sourcemaps)
19 | * Modular javascript (Sourcemaps)
20 | * Auto image-optimization
21 | * Sitemap-generator
22 | * Autoreload
23 | * Tunnel(expose localhost to public URL)
24 | * Proxy
25 | * PageSpeed Insights reporting
26 | * Remove unused CSS
27 |
28 |
29 | ## Installation ##
30 |
31 | If you have not already installed nodejs and npm: [https://nodejs.org/](https://nodejs.org/ "https://nodejs.org/")
32 |
33 | If you have not already installed git: [https://git-scm.com](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git "https://git-scm.com/book/en/v2/Getting-Started-Installing-Git") (Optional)
34 |
35 | Install gulp-cli via Terminal.
36 |
37 | ```
38 | npm install --g gulp-cli
39 | ```
40 |
41 |
42 | ## Setup ##
43 |
44 | Clone this repository via Terminal. Or just click on the download-button in the right corner...
45 |
46 | ```
47 | git clone https://github.com/koljakutschera/yafbp && cd yafbp
48 | ```
49 |
50 | Install dependencies via Terminal(Maybe sudo is needed).
51 |
52 | ```
53 | npm install
54 | ```
55 |
56 |
57 | ## Configuration ##
58 |
59 | You can configure the process-settings in /gulpfile.js:
60 |
61 | Example: Default configuration
62 |
63 | ```javascript
64 | var config = {
65 | source_dir : './source/',
66 | build_dir : './build/',
67 | statics_dir : 'statics/',
68 | templates_dir : 'templates/',
69 | data_dir : 'data/',
70 | styles_dir : 'styles/',
71 | scripts_dir : 'scripts/',
72 | images_dir : 'images/',
73 | connect_port : 8080,
74 | proxy_port : 9090,
75 | proxyAuth : '',
76 | autoprefix : ["> 1%","last 4 versions"]
77 | }
78 | ```
79 |
80 |
81 | ## Usage ##
82 |
83 | In the project-directory start the development process via Terminal:
84 |
85 | > Hint: All commands starting with -- can be combined.
86 |
87 | ```
88 | gulp
89 | ```
90 |
91 | Or with minification for styles, scripts, images and html.
92 |
93 | ```
94 | gulp --production
95 | ```
96 |
97 | Or with removing all unused styles.
98 |
99 | ```
100 | gulp --purify
101 | ```
102 |
103 | Or with exposing localhost to public URL(See public development covered in the next section)
104 |
105 | ```
106 | gulp --tunnel
107 | ```
108 |
109 | Or with [PageSpeed-Insights](https://developers.google.com/speed/pagespeed/insights/) reports for all pages(could take a few minutes...)
110 |
111 | ```
112 | gulp --production --tunnel --psi
113 | ```
114 |
115 |
116 | ## Development ##
117 |
118 | ### Local development ###
119 |
120 | When the process is running open the following url in your browser:
121 |
122 | ```
123 | http://localhost:8080
124 | ```
125 |
126 | ### Public development ###
127 |
128 | When using --tunnel flag you can also access your project via temporary public URL.
129 | With this you can for example check your site with [browserstack](https://www.browserstack.com/) or send the link to your customer for live-testing.
130 |
131 | > Hint: On every process start you get a new temporary public URL. You can see it in terminal logs.
132 |
133 | Example: See terminal logs for public URL
134 | ```
135 | Exposing localhost:8080 via public URL: https://temorary123.eu.ngrok.io
136 | ```
137 |
138 |
139 | ## Templating ##
140 |
141 | In **source/templates** [Nunjucks](https://mozilla.github.io/nunjucks/templating.html "Nunjucks") is used for templating with all its features like block inheritance(layouts), autoescaping, macros and more.
142 | Every(except for files starting with an _) .html file on the root-level of the directory is compiled to the build/ directory. Templates on the root-level are your "pages".
143 | Files in sub-directories are ignored, but can be included in root-templates via Nunjucks [template-inheritance-system](https://mozilla.github.io/nunjucks/templating.html#template-inheritance "Nunjucks template-inheritance").
144 |
145 | > Info: The default directory structure is only a recommendation - feel free to delete everything and start from scratch.
146 |
147 | > Hint: Files starting with an _ will not compile. Use this for drafts etc.
148 |
149 | Example: Simple layout
150 |
151 | ```html
152 |
153 |
154 |
215 |
216 |
217 |
218 |
219 | ```
220 |
221 | See [https://mozilla.github.io/nunjucks/](https://mozilla.github.io/nunjucks/) for more.
222 |
223 | ### Template helpers ###
224 |
225 | You can use the following included helpers in your nunjucks templates and macros:
226 | * [moment.js](http://momentjs.com/) - Parse, validate, manipulate, and display dates.
227 | * [accounting.js](http://openexchangerates.github.io/accounting.js/) - number, money and currency formatting
228 |
229 | > Hint: You can add your own helpers to the global data object covered in the next section.
230 |
231 |
232 | Example: Formating a date-string with moment.js
233 |
234 | ```html
235 | {{moment("2017-09-20").locale('de').format('LL')}}
236 | ```
237 |
238 | Result: Showing formatted German date
239 |
240 | ```html
241 | 20. September 2017
242 | ```
243 |
244 |
245 | Example: Formating money with accounting.js
246 |
247 | ```html
248 | {{ accounting.formatMoney(4999.99, "€", 2, ".", ",") }}
249 | ```
250 |
251 | Result: Showing formatted money
252 |
253 | ```html
254 | €4.999,99
255 | ```
256 |
257 |
258 | ## Template data layer ##
259 |
260 | ### Global data ###
261 |
262 | In **data/index.js** you can define your own data-sets and export it to all your templates.
263 | Think about generating navigation from json or exposing data from a csv-files that is read via nodejs.
264 | Global data is accessible in templates via "global" variable.
265 | The data is also written to build/data.json for ajax-access.
266 |
267 | > Info: The default directory structure in data/ is only a recommendation - feel free to delete everything except for data/index.js and start from scratch.
268 |
269 | > Help: There is a helper-function in data/index.js to import node-modules un-cached. Use this if you always want fresh data on every file-change.
270 |
271 | > Hint: You can dump the global data with: {{ global | dump }}
272 |
273 | Example: Export site-url to all templates.
274 |
275 | ```javascript
276 | var global = {
277 | siteUrl : 'http://www.change-to-yourdomain.de' // Required for sitemap.xml - do not delete!
278 | };
279 |
280 | // Expose data to templates
281 | module.exports = global;
282 | ```
283 |
284 | Example: Access site-url in page:
285 |
286 | ```html
287 |
294 | ```
295 |
296 |
297 | ### Per page data ###
298 |
299 | You can also provide data directly to a page via **YAML-Front-Matter** at the top of root-templates.
300 | This data is accessible in the template via "page" variable.
301 |
302 | > Hint: You can dump the data of a page with: {{ page | dump }}
303 |
304 | Example: YAML-Front-Matter at the top of a page:
305 |
306 | ```
307 | ---
308 | title: Home
309 | ---
310 | ```
311 |
312 | Example: Access YAML-Front-Matter from page in layout template:
313 |
314 | ```html
315 | {{ page.title }}
316 | ```
317 |
318 | Result:
319 |
320 | ```html
321 | Home
322 | ```
323 |
324 | ### All pages data ###
325 |
326 | All the data you have provided to all root-templates via YAML-Front-Matter is also accessible in all other templates via "pages"-variable.
327 | The data is also written to build/data.json for ajax-access.
328 | You can access data from another page by the name of the template without the .html extension.
329 |
330 | > Info: This gives you almost all possibilities you want from a static-page-generator.
331 |
332 | > Hint: You can dump the data of all pages with: {{ pages | dump }}
333 |
334 | Example: Access data of another page in a page:
335 |
336 | ```html
337 |
Every little page knows the path of the index-page: {{ pages.index.path }}
Every little page knows the title of the index-page: index.html
344 | ```
345 |
346 |
347 | ## Sitemap-generator ##
348 |
349 | For our SEOs all .html files on the root-level of **source/templates** are indexed to the sitemap.xml-file in the build/ directory. Files starting with an _ are excluded.
350 |
351 |
352 | ## Modular less-stylesheets ##
353 |
354 | In **source/styles** every(except for files starting with an _) .less file on the root-level of the directory is compiled to the build/styles/ directory.
355 | Files in sub-directories are ignored, but can be imported in root-stylesheets via less-imports.
356 |
357 | For example and depending on your needs you can use one core.less file and import all stylesheets in it for single-page-apps. Or you can use the core.less file for shared styles and multiple other files for per-page styles in a multi-page setup.
358 |
359 | > Hot: Styles are hot-reloaded(See file-changes without reloading the browser);
360 |
361 | > Info: The default directory structure is only a recommendation - feel free to delete everything and start from scratch.
362 |
363 | > Hint: You can also pass options to less-imports. [http://lesscss.org/](http://lesscss.org/features/#import-options "import-options")
364 |
365 | Example: Importing another stylesheet.
366 |
367 | ```less
368 | @import "tools/reset.less";
369 | ```
370 |
371 | See [http://lesscss.org/](http://lesscss.org/) for more.
372 |
373 |
374 | ## CSS-Autoprefixer ##
375 |
376 | When writing less/css browser-prefixes are automatically added. You can configure browser-versions in /gulpfile.js
377 |
378 |
379 | ## Modular javascript ##
380 |
381 | In **source/scripts** every(except for files starting with an _) .js-file on the root-level of the directory is compiled to the build/scripts/ directory.
382 | Files in sub-directories are ignored, but can be included in root-scripts via a special comment/directive.
383 |
384 | Depending on your needs you can use one core.js file and require all libs and scripts in it for single-page-apps. Or you can use the core.js file for shared libraries and multiple other files for per-page scripts in a multi-page setup.
385 |
386 | > Info: The default directory structure is only a recommendation - feel free to delete everything and start from scratch.
387 |
388 | > Hint: Script including works recursively (files can include files that can include files, and so on)
389 |
390 | Example: Importing another script.
391 |
392 | ```javascript
393 | //=require tools/log.js
394 | ```
395 |
396 | See [https://www.npmjs.com/package/gulp-include](https://www.npmjs.com/package/gulp-include) for more.
397 |
398 | ## Auto image-optimization ##
399 |
400 | In **source/images** every .jpg, .png, .gif and .svg file is compiled/optimized to the build/images/ directory.
401 |
402 | > The default directory structure is only a recommendation - feel free to delete everything and start from scratch.
403 |
404 |
405 | ## Static Files ##
406 |
407 | In **source/statics** you can put fonts, media etc. Every file and directory is copied to the build/statics/ directory.
408 |
409 |
410 | ## Proxy ##
411 |
412 | The proxy is listening on port: 9090. Use it for example if you cant access an api-endpoint via ajax because of Cross-Origin Resource Sharing (CORS).
413 |
414 | > Hint: You can add http-authentication to the proxy in /gulpfile.js
415 |
416 | Example: Proxy usage with jQuery:
417 |
418 | ```javascript
419 | var proxy = 'http://localhost:9090/';
420 | var endpoint = 'www.echojs.com/'; // change this to your api-endpoint.
421 |
422 | $.getJSON(proxy + endpoint, function( data ) {
423 | console.log(data)
424 | });
425 | ```
426 |
427 | ## Auto-reload ##
428 |
429 | When the build process is started a file-watcher watches for file-changes and auto-reloads the browser every time you change a file. Sometimes on first start you have to do a manual reload because the process is faster than the browser.
430 |
431 |
432 | ## Where do I start? ##
433 |
434 | Just look at the contents of the source/ directory.
435 | There are just a few example files that should be self-documenting.
436 |
437 | If you want a more advanced example checkout: [yafbp-example-blog](https://github.com/koljakutschera/yafbp-example-blog)
438 |
439 | To start from scratch - You can delete everything in source/images/, source/scripts/, source/styles/, source/templates/ directories. In the data/ directory only /index.js is required.
440 | For scripts and styles remember that files on the root-level act as entry-points.
441 |
442 | Feel free to configure anything in /gulpfile.js to your needs.
443 |
444 | ## Contribution ##
445 |
446 | Please don't! Except for bugs. Iam not interested in extending this project with more crazy stuff to increase its complexity.
447 | If you want babel, react or your shiny whatever JS-Framework just fork this repo and put it in the source directory :P
448 |
449 |
450 | ## Thank you ##
451 |
452 | Thank you to all funky developers listed in /package.json.
453 |
454 |
455 | ## History ##
456 |
457 | * V1.2.4: Write external source map files
458 | * V1.2.3: Remove unused CSS with --purify command. See readme -> Usage
459 | * V1.2.2: Optimized watchers for slow file-systems
460 | * V1.2.1: Configuration added. See readme.md -> Configuration
461 | * V1.2.0: Added PageSpeed Insights reporting feature. See readme.md -> Usage
462 | * V1.1.0: Added Tunnel(expose localhost to public URL) feature. See readme.md
463 | * V1.0.2: Global- and pages data objects are now nunjucks-globals so that they can be used in macros too. Cache optimized.
464 | * V1.0.1: Added Template helpers(moment.js, accounting.js). See readme.md
465 | * V1.0.0: Dropped SVGInjector for simplicity, Data-layer extended with global, page, pages variables, Added sitemap-generator, Simplify examples, Using _ in filenames for drafts, removed build/ from .gitignore
466 |
467 |
468 | ## Troubleshooting ##
469 |
470 | Linux: The system has a limit to how many files can be watched by a user. The following command increases the maximum amount of watches a user can have:
471 |
472 | ```
473 | echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
474 | ```
475 |
--------------------------------------------------------------------------------
/build/data.json:
--------------------------------------------------------------------------------
1 | {
2 | "global": {
3 | "siteUrl": "http://www.change-to-your-domain.de"
4 | },
5 | "pages": {
6 | "index": {
7 | "title": "Home",
8 | "path": "index.html"
9 | }
10 | }
11 | }
--------------------------------------------------------------------------------
/build/images/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brokolja/yafbp/ab2a1e01fd526b78ddade191b349d3facda66087/build/images/screenshot.png
--------------------------------------------------------------------------------
/build/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Home
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |