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

"title": "Spus", "title": "Spus",
"base_url": "http://example.com", "base_url": "http://example.com",
"port": 8081, "port": 8081,

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

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

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

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

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

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

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

# In debug mode, an uncaught exception will stop the program and display
# a neat stack trace.
"debug": false, "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, "max_runs": 9999,

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

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

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

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

+ 1
- 0
lib/minify.js View File

return minifyHtml(src, { return minifyHtml(src, {
removeComments: true, removeComments: true,
collapseWhitespace: true, collapseWhitespace: true,
minifyJS: true
}); });
} }



+ 18
- 1
lib/preprocess.js View File

var localRegex = new RegExp(regexStr); var localRegex = new RegExp(regexStr);
var globalRegex = new RegExp(regexStr, "g"); 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) { function getVal(str, env) {
if (vals.env.test(str)) { if (vals.env.test(str)) {
var parts = str.split("#"); var parts = str.split("#");
if (typeof ns === "function") if (typeof ns === "function")
return ns(parts[1]); return ns(parts[1]);
else if (ns !== undefined) else if (ns !== undefined)
return ns[parts[1]];
return getObjVal(ns, parts[1]);
else else
throw new Error("No: "+str); throw new Error("No: "+str);
} else if (vals.string.test(str)) { } else if (vals.string.test(str)) {

+ 1
- 1
server.js View File

var loader = require("./lib/loader.js"); var loader = require("./lib/loader.js");
var Context = require("./lib/context.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 = { var endpoints = {



+ 2
- 0
templates/head.html View File

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" defer></script> <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="/global.js?{{conf#current_run}}" defer></script>
<script src="/{{env#view}}/script.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

<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