Browse Source

Open Web Analytics integration, comments in config

master
mort 8 years ago
parent
commit
2adf47db84
6 changed files with 74 additions and 2 deletions
  1. 35
    0
      conf.json.example
  2. 1
    0
      lib/minify.js
  3. 18
    1
      lib/preprocess.js
  4. 1
    1
      server.js
  5. 2
    0
      templates/head.html
  6. 17
    0
      templates/open-web-analytics.html

+ 35
- 0
conf.json.example View File

@@ -2,30 +2,65 @@
"title": "Spus",
"base_url": "http://example.com",
"port": 8081,

# PostrgeSQL credentials
"db": {
"host": "localhost",
"user": "dbuser",
"password": "dbpass",
"database": "spus"
},

# HTTPS settings
"use_https": false,
"https": {
"key": "",
"cert": ""
},

# Open Web Analytics settings
"use_owa": false,
"owa": {
"base_url": "",
"site_id": ""
},

# Scrypt settings for password hashing
"scrypt": {
"maxtime": 1
},

# Should we minify resources?
"minify": true,

# Timeout in milliseconds before a session is destroyed
"session_timeout": 1800000,

# Various directories
"dir": {
"imgs": "imgs",
"web": "web"
},

# In debug mode, an uncaught exception will stop the program and display
# a neat stack trace.
"debug": false,

# To invalidate cache, we add "?$n" to static resource requests
# (scripts, CSS, etc.), where "$n" is an incrementing number.
# `max_runs` is how big $n can be before we reset to 0.
"max_runs": 9999,

# Time in seconds before static content caches are invalidated
"cache_max_age": 2628000,

# Time in seconds before image caches are invalidated
"cache_max_age_images": 2628000,

# How long time it should take before anonymous images are deleted
"purge_collections_timeout": "2 days",

# Time in milliseconds between each time we query the database for old
# anonymous pictures
"purge_collections_interval": 1800000
}

+ 1
- 0
lib/minify.js View File

@@ -6,6 +6,7 @@ exports.html = function(src) {
return minifyHtml(src, {
removeComments: true,
collapseWhitespace: true,
minifyJS: true
});
}


+ 18
- 1
lib/preprocess.js View File

@@ -28,6 +28,23 @@ var regexStr =
var localRegex = new RegExp(regexStr);
var globalRegex = new RegExp(regexStr, "g");

function getObjVal(obj, str) {
var val = obj[str];
if (val !== undefined)
return val;

var parts = str.split(".");

val = obj;
for (var i = 0; i < parts.length; ++i) {
val = val[parts[i]];
if (val === undefined)
return undefined;
}

return val;
}

function getVal(str, env) {
if (vals.env.test(str)) {
var parts = str.split("#");
@@ -36,7 +53,7 @@ function getVal(str, env) {
if (typeof ns === "function")
return ns(parts[1]);
else if (ns !== undefined)
return ns[parts[1]];
return getObjVal(ns, parts[1]);
else
throw new Error("No: "+str);
} else if (vals.string.test(str)) {

+ 1
- 1
server.js View File

@@ -9,7 +9,7 @@ var log = require("mlogger");
var loader = require("./lib/loader.js");
var Context = require("./lib/context.js");

var conf = JSON.parse(fs.readFileSync("conf.json"));
var conf = JSON.parse(fs.readFileSync("conf.json", "utf8").replace(/^\s*#.+/gm, ""));

var endpoints = {


+ 2
- 0
templates/head.html View File

@@ -10,3 +10,5 @@
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" defer></script>
<script src="/global.js?{{conf#current_run}}" defer></script>
<script src="/{{env#view}}/script.js?{{conf#current_run}}" defer></script>

{{conf#use_owa ? template#open-web-analytics : ''}}

+ 17
- 0
templates/open-web-analytics.html View File

@@ -0,0 +1,17 @@
<script type="text/javascript">
//<![CDATA[
var owa_baseUrl = '{{conf#owa.base_url}}';
var owa_cmds = owa_cmds || [];
owa_cmds.push(['setSiteId', '{{conf#owa.site_id}}']);
owa_cmds.push(['trackPageView']);
owa_cmds.push(['trackClicks']);
owa_cmds.push(['trackDomStream']);

(function() {
var _owa = document.createElement('script'); _owa.type = 'text/javascript'; _owa.async = true;
owa_baseUrl = ('https:' == document.location.protocol ? window.owa_baseSecUrl || owa_baseUrl.replace(/http:/, 'https:') : owa_baseUrl );
_owa.src = owa_baseUrl + 'modules/base/js/owa.tracker-combined-min.js';
var _owa_s = document.getElementsByTagName('script')[0]; _owa_s.parentNode.insertBefore(_owa, _owa_s);
}());
//]]>
</script>

Loading…
Cancel
Save