https://github.com/angeal185/ghost-minify-output
ghost middleware to minify compiled handlebars output
https://github.com/angeal185/ghost-minify-output
ghost ghost-blog ghost-cms minification minify nodejs
Last synced: 10 months ago
JSON representation
ghost middleware to minify compiled handlebars output
- Host: GitHub
- URL: https://github.com/angeal185/ghost-minify-output
- Owner: angeal185
- Created: 2017-06-14T03:45:39.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-14T05:22:29.000Z (about 9 years ago)
- Last Synced: 2025-04-13T05:44:41.652Z (about 1 year ago)
- Topics: ghost, ghost-blog, ghost-cms, minification, minify, nodejs
- Language: JavaScript
- Size: 16.6 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ghost-minify-output
ghost middleware to minify compiled handlebars output and to disable beautify
## Instructions
### minification setup
- Open a console in ghost root dir [`/ghost`] and type:
````
npm install --save html-minifier
````
- Add the file `settings.json` to your root dir.
- Add the file `minify.js` to `ghost/core/server/middleware/`
- Open the file `index.js` located at`ghost/core/server/middleware/`
- Add thefollowing 2 lines of code to the list of required modules:
(refer to the `example/index.js` file included in this repo if you dont understand)
````
settings = require('../../../settings.json'),
minifyOutput = require('./minify'),
````
Find the following lines in of code in the same file:
````
adminApp.set('view engine', 'hbs');
adminApp.engine('hbs', adminHbs.express3({}));
````
- Below the above mentioned lines add the following 4 lines of code
````
if (settings.minifyOutput === true) {
//minify html output
blogApp.use(minifyOutput);
}
````
You can now enable/disable minification in the `/ghost/settings.json` file.
- `true` = on
- `false` = off
### beautify setup
(refer to the `example/theme-handler.js` file included in this repo if you dont understand)
- Open the file `theme-handler.js` located at`ghost/core/server/middleware/`
- Find the following lines of code:
````
activateTheme: function activateTheme(blogApp, activeTheme) {
var hbsOptions,
````
- Below the above mentioned lines add the following 2 lines of code
````
settings = require('../../../settings.json'),
beautify = settings.beautify,
````
- Find the following lines of code:
````
hbsOptions = {
partialsDir: [config.paths.helperTemplates],
onCompile: function onCompile(exhbs, source) {
return exhbs.handlebars.compile(source, {preventIndent: true});
}
};
````
- Replace the above mentioned lines with the following lines of code
````
hbsOptions = {
partialsDir: [config.paths.helperTemplates],
onCompile: function onCompile(exhbs, source) {
return exhbs.handlebars.compile(source, {preventIndent: true});
},
beautify
};
````
You can now enable/disable beautify in the `/ghost/settings.json` file.
- `true` = on
- `false` = off
Done.