diff --git a/.gitignore b/.gitignore index 3ea4f5c..08d70a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ *.tmp /Build/* /node_modules/* -/Example.Server.html +/Example.Server/index.html diff --git a/Example.css b/Example.Server/index.css similarity index 100% rename from Example.css rename to Example.Server/index.css diff --git a/Example.Server.js b/Example.Server/index.js similarity index 87% rename from Example.Server.js rename to Example.Server/index.js index 95bd3ce..6a4520b 100755 --- a/Example.Server.js +++ b/Example.Server/index.js @@ -1,18 +1,20 @@ #!/usr/bin/env node -const SpaccDotWebServer = require('./SpaccDotWeb.Server.js'); +const SpaccDotWebServer = require('../SpaccDotWeb.Server.js'); const server = SpaccDotWebServer.setup({ appName: 'Example', // staticPrefix: '/static/', + // staticRoot: '', // not (yet) implemented // staticFiles: [], - linkStyles: [ 'Example.css' ], - // linkScripts: [], + linkStyles: [ 'index.css' ], + // linkRuntimeScripts: [], // not (yet) implemented + linkClientScripts: [ 'particles.js' ], // pageTitler: (title, opts={}) => `...`, // appPager: (content, title, opts={}) => `...`, // htmlPager: (content, title, opts={}) => `...`, }); -if (SpaccDotWebServer.envIsNode && ['dump', 'html'].includes(process.argv[2])) { - const fileName = server.writeStaticHtml(); +if (SpaccDotWebServer.envIsNode && ['dump', 'html', 'writeStaticHtml'].includes(process.argv[2])) { + const fileName = server.writeStaticHtml(Number(process.argv[3] || 0)); console.log(`Dumped Static HTML to '${fileName}'!`); } else { const serverData = server.initServer({ diff --git a/Example.Server/particles.js b/Example.Server/particles.js new file mode 100644 index 0000000..2269b16 --- /dev/null +++ b/Example.Server/particles.js @@ -0,0 +1,17 @@ +window.addEventListener('load', function(){ + for (var i=0; i<(window.innerWidth * window.innerHeight / 6000); i++) (function(){ + var v = (Math.random() * window.innerHeight), h = (100 * Math.random()); + var n = document.createElement('span'); + n.textContent = '✨️'; + n.style.position = 'absolute'; + document.body.appendChild(n); + var e = setInterval(function(){ + var r = Math.random(); + n.style.top = (v += 1).toString() + 'px'; + n.style.left = (h += (r > 0.7 ? r/5 : -r/5)).toString() + '%'; + if (v > window.innerHeight) v = -16; + if (h > 100) h = -2; + else if (h < -2) h = 100; + }, 20); + })(); +}); diff --git a/SpaccDotWeb.Server.js b/SpaccDotWeb.Server.js index 857e2c1..2ddafb7 100644 --- a/SpaccDotWeb.Server.js +++ b/SpaccDotWeb.Server.js @@ -1,12 +1,10 @@ /* TODO: * built-in logging - * configure to embed linked styles and scripts into the HTML output, or just link to file - * handle linkScripts to insert in the HTML, like linkStyles - * differentiate between client-only, served-only, and both-mode scripts? - * relative URL root + * relative URL root for redirects and internal functions? (or useless since HTML must be custom anyways?) * utility functions for rewriting url query parameters? * fix hash navigation to prevent no-going-back issue (possible?) * finish polishing the cookie API + * implement some nodejs `fs` functions for client-side * other things listed in the file */ (() => { @@ -24,11 +22,14 @@ const cookieMaxAge2Years = (2 * 365 * 24 * 60 * 60); const setup = (globalOptions={}) => { allOpts.global = globalOptions; //allOpts.global.appName ||= 'Untitled SpaccDotWeb App'; + //allOpts.global.appRoot ||= ''; //TODO allOpts.global.staticPrefix ||= '/static/'; + //allOpts.global.staticRoot ||= ''; //TODO allOpts.global.staticFiles ||= []; allOpts.global.linkStyles ||= []; - allOpts.global.linkScripts ||= []; - for (const item of [...allOpts.global.linkStyles, ...allOpts.global.linkScripts]) { + //allOpts.global.linkRuntimeScripts ||= []; //TODO + allOpts.global.linkClientScripts ||= []; + for (const item of [ ...allOpts.global.linkStyles, ...allOpts.global.linkClientScripts ]) { const itemLow = item.toLowerCase(); if (!(itemLow.startsWith('http://') || itemLow.startsWith('https://') || itemLow.startsWith('/'))) { allOpts.global.staticFiles.push(item); @@ -40,9 +41,8 @@ const setup = (globalOptions={}) => { -->${(opts.pageTitler || allOpts.global.pageTitler)(title, opts)}${allOpts.global.linkStyles.map((item) => { - return ``; - }).join('')}${allOpts.global.linkStyles.map((path) => makeHtmlStyleFragment(path, opts.selfContained)).join('')}${allOpts.global.linkClientScripts.map((path) => makeHtmlScriptFragment(path, opts.selfContained)).join('')}
${(opts.appPager || allOpts.global.appPager)(content, title, opts)}