Skip to content

Commit 5ac4fcf

Browse files
committed
Add .env support for rednering context
Add google analytics code
1 parent e4cd885 commit 5ac4fcf

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ npm-debug.log
2424

2525
*.iml
2626
/dist
27+
/.env

build/tasks/app-pages.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var through = require('through2');
55
var File = require('vinyl');
66
var StringDecoder = require('string_decoder').StringDecoder;
77
var extend = require('util')._extend;
8+
var dotenv = require('dotenv');
89

910
var frontMatter = require('front-matter');
1011
var handlebars = require('handlebars');
@@ -152,6 +153,8 @@ function setFrontMatter(file) {
152153
This function returns context of current page
153154
which is root context extended by all contexts untill
154155
current level context
156+
157+
You may also use .env file in root folder
155158
*/
156159

157160

@@ -160,6 +163,15 @@ function getPageContextExternal(file) {
160163
// Initial context
161164
var context = {};
162165

166+
// Environmental variables
167+
env = dotenv.config({
168+
silent: true,
169+
path: path.resolve(config.rootDir, '.env')
170+
});
171+
172+
//
173+
extend(context, env);
174+
163175
// Package data
164176
context.pkg = require('../../package.json');
165177

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
"url": "https://github.com/modularcode/modular-admin-html/issues"
1313
},
1414
"homepage": "https://github.com/modularcode/modular-admin-html",
15-
"dependencies": {},
15+
"dependencies": {
16+
},
1617
"devDependencies": {
18+
"dotenv": "^2.0.0",
1719
"front-matter": "^2.0.5",
1820
"fs-extra": "^0.26.4",
1921
"glob": "^5.0.14",

src/_main-layout.hbs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ title: ModularAdmin - Free Dashboard Theme | HTML Version
4040
<div class="color-secondary"></div>
4141
</div>
4242
</div>
43+
{{!-- Google Analytics code if GOOGLE_ANALYTICS_ID id available --}}
44+
{{#if GOOGLE_ANALYTICS_ID}}
45+
<script>
46+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
47+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
48+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
49+
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
50+
51+
ga('create', '{{GOOGLE_ANALYTICS_ID}}', 'auto');
52+
ga('send', 'pageview');
53+
54+
</script>
55+
{{/if}}
4356
<script src="js/vendor.js"></script>
4457
<script src="js/app.js"></script>
4558
</body>

0 commit comments

Comments
 (0)