legacyweb-pages 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
- # legacyweb-pages
2
-
3
- This is a toolkit for generating simple pages for legacyweb.
4
-
1
+ # legacyweb-pages
2
+
3
+ This is a toolkit for generating simple pages for legacyweb.
4
+
5
5
  It includes templates, themes, and functions for generating pages based on these. This project is currently under development.
package/index.js CHANGED
@@ -1,3 +1,3 @@
1
- const Page = require('./lib/page');
2
-
3
- module.exports = Page;
1
+ const Page = require('./lib/page');
2
+
3
+ module.exports = Page;
package/lib/page.js CHANGED
@@ -1,129 +1,129 @@
1
- const ejs = require('ejs');
2
- const express = require('express');
3
- const fs = require('fs');
4
- const path = require('path');
5
- const joi = require('joi');
6
-
7
- const relativePath = joi.string().regex(/^\/[a-zA-Z0-9\/?=]*$/);
8
-
9
- function Page(template, theme, title, home, addHomeLink=true, staticPaths=[]) {
10
- this.setTemplate(template);
11
- this.setTheme(theme);
12
- this.pages = [];
13
- this.links = [];
14
- this.addPage({
15
- path: '/',
16
- gen: home.gen,
17
- title,
18
- method: 'get'
19
- });
20
- if (addHomeLink) {
21
- this.addLink({
22
- url: '/',
23
- text: 'Home'
24
- });
25
- }
26
- this.headerHtml = '';
27
- this.port = process.env.EXPRESS_PORT || 3000;
28
- this.app = express();
29
-
30
- // Pre-defined static paths
31
- this.app.use('/images', express.static(path.join(__dirname, '..', 'images')));
32
-
33
- // Define static paths
34
- staticPaths.forEach(staticPath => {
35
- this.app.use(staticPath.webPath, express.static(staticPath.filePath));
36
- });
37
- }
38
-
39
- Page.prototype.setTemplate = function(template) {
40
- const templateFile = path.join(__dirname, '..', 'templates', `${template}.ejs`);
41
- if (!fs.existsSync(templateFile)) {
42
- throw new Error(`Theme "${templateFile}" does not exist`);
43
- }
44
- this.template = fs.readFileSync(templateFile, 'utf-8');
45
- }
46
-
47
- Page.prototype.setTheme = function(theme) {
48
- const themeFile = path.join(__dirname, '..', 'themes', `${theme}.json`);
49
- if (!fs.existsSync(themeFile)) {
50
- throw new Error(`Theme "${theme}" does not exist`);
51
- }
52
- this.theme = JSON.parse(fs.readFileSync(themeFile), 'utf-8');
53
- }
54
-
55
- Page.prototype.setBgImage = function(element, bgImage) {
56
- joi.attempt(element, joi.string().valid('body', 'links', 'strip', 'content'));
57
- this.theme[element].bgImage = bgImage;
58
- }
59
-
60
- Page.prototype.setHeader = function(code) {
61
- this.headerHtml = code;
62
- }
63
-
64
- Page.prototype.setStrip = function(code) {
65
- this.stripHtml = code;
66
- }
67
-
68
- Page.prototype.addLink = function(link) {
69
- joi.attempt(link, joi.object({
70
- url: joi.string().min(1).required(),
71
- text: joi.string().min(1).required()
72
- }));
73
- this.links.push(link);
74
- }
75
-
76
- Page.prototype.addPage = function(page) {
77
- let validatedPage = joi.attempt(page, joi.object({
78
- path: joi.string().min(1).required(),
79
- gen: joi.func().required(),
80
- title: joi.string().min(1).required(),
81
- method: joi.string().valid('get', 'post').default('get'),
82
- middleware: joi.array().default([])
83
- }));
84
-
85
- this.pages.push(validatedPage);
86
- }
87
-
88
- Page.prototype.start = function() {
89
-
90
- const legacyPage = this;
91
-
92
- this.pages.forEach(page => {
93
- const renderPage = async function(req, res) {
94
- try {
95
- // Render content first in case we want to change the theme, header, etc. as part of the gen fn
96
- const content = await page.gen(req, res);
97
-
98
- const data = Object.assign({
99
- page: {
100
- header: legacyPage.headerHtml,
101
- strip: legacyPage.stripHtml,
102
- title: page.title,
103
- links: legacyPage.links,
104
- content
105
- }
106
- }, legacyPage.theme);
107
- const renderedPage = ejs.render(legacyPage.template, data);
108
-
109
- res.status(200).send(renderedPage);
110
- } catch (err) {
111
- const statusCode = err.status || 500;
112
- return res.status(statusCode).send(err.message);
113
- }
114
- }
115
-
116
- switch (page.method) {
117
- case 'post':
118
- legacyPage.app.post(page.path, page.middleware, renderPage);
119
- return;
120
- default:
121
- legacyPage.app.get(page.path, page.middleware, renderPage);
122
- return;
123
- }
124
- });
125
-
126
- this.app.listen(this.port);
127
- }
128
-
129
- module.exports = Page
1
+ const ejs = require('ejs');
2
+ const express = require('express');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const joi = require('joi');
6
+
7
+ const relativePath = joi.string().regex(/^\/[a-zA-Z0-9\/?=]*$/);
8
+
9
+ function Page(template, theme, title, home, addHomeLink=true, staticPaths=[]) {
10
+ this.setTemplate(template);
11
+ this.setTheme(theme);
12
+ this.pages = [];
13
+ this.links = [];
14
+ this.addPage({
15
+ path: '/',
16
+ gen: home.gen,
17
+ title,
18
+ method: 'get'
19
+ });
20
+ if (addHomeLink) {
21
+ this.addLink({
22
+ url: '/',
23
+ text: 'Home'
24
+ });
25
+ }
26
+ this.headerHtml = '';
27
+ this.port = process.env.EXPRESS_PORT || 3000;
28
+ this.app = express();
29
+
30
+ // Pre-defined static paths
31
+ this.app.use('/images', express.static(path.join(__dirname, '..', 'images')));
32
+
33
+ // Define static paths
34
+ staticPaths.forEach(staticPath => {
35
+ this.app.use(staticPath.webPath, express.static(staticPath.filePath));
36
+ });
37
+ }
38
+
39
+ Page.prototype.setTemplate = function(template) {
40
+ const templateFile = path.join(__dirname, '..', 'templates', `${template}.ejs`);
41
+ if (!fs.existsSync(templateFile)) {
42
+ throw new Error(`Theme "${templateFile}" does not exist`);
43
+ }
44
+ this.template = fs.readFileSync(templateFile, 'utf-8');
45
+ }
46
+
47
+ Page.prototype.setTheme = function(theme) {
48
+ const themeFile = path.join(__dirname, '..', 'themes', `${theme}.json`);
49
+ if (!fs.existsSync(themeFile)) {
50
+ throw new Error(`Theme "${theme}" does not exist`);
51
+ }
52
+ this.theme = JSON.parse(fs.readFileSync(themeFile), 'utf-8');
53
+ }
54
+
55
+ Page.prototype.setBgImage = function(element, bgImage) {
56
+ joi.attempt(element, joi.string().valid('body', 'links', 'strip', 'content'));
57
+ this.theme[element].bgImage = bgImage;
58
+ }
59
+
60
+ Page.prototype.setHeader = function(code) {
61
+ this.headerHtml = code;
62
+ }
63
+
64
+ Page.prototype.setStrip = function(code) {
65
+ this.stripHtml = code;
66
+ }
67
+
68
+ Page.prototype.addLink = function(link) {
69
+ joi.attempt(link, joi.object({
70
+ url: joi.string().min(1).required(),
71
+ text: joi.string().min(1).required()
72
+ }));
73
+ this.links.push(link);
74
+ }
75
+
76
+ Page.prototype.addPage = function(page) {
77
+ let validatedPage = joi.attempt(page, joi.object({
78
+ path: joi.string().min(1).required(),
79
+ gen: joi.func().required(),
80
+ title: joi.string().min(1).required(),
81
+ method: joi.string().valid('get', 'post').default('get'),
82
+ middleware: joi.array().default([])
83
+ }));
84
+
85
+ this.pages.push(validatedPage);
86
+ }
87
+
88
+ Page.prototype.start = function() {
89
+
90
+ const legacyPage = this;
91
+
92
+ this.pages.forEach(page => {
93
+ const renderPage = async function(req, res) {
94
+ try {
95
+ // Render content first in case we want to change the theme, header, etc. as part of the gen fn
96
+ const content = await page.gen(req, res);
97
+
98
+ const data = Object.assign({
99
+ page: {
100
+ header: legacyPage.headerHtml,
101
+ strip: legacyPage.stripHtml,
102
+ title: page.title,
103
+ links: legacyPage.links,
104
+ content
105
+ }
106
+ }, legacyPage.theme);
107
+ const renderedPage = ejs.render(legacyPage.template, data);
108
+
109
+ res.status(200).send(renderedPage);
110
+ } catch (err) {
111
+ const statusCode = err.status || 500;
112
+ return res.status(statusCode).send(err.message);
113
+ }
114
+ }
115
+
116
+ switch (page.method) {
117
+ case 'post':
118
+ legacyPage.app.post(page.path, page.middleware, renderPage);
119
+ return;
120
+ default:
121
+ legacyPage.app.get(page.path, page.middleware, renderPage);
122
+ return;
123
+ }
124
+ });
125
+
126
+ this.app.listen(this.port);
127
+ }
128
+
129
+ module.exports = Page
package/lib/theme.js CHANGED
@@ -1,46 +1,46 @@
1
- const joi = require('joi');
2
-
3
- function Theme(theme) {
4
- const schema = joi.object({
5
- body: joi.object({
6
- bgColor: joi.string().default('white'),
7
- bgImage: joi.string().optional(),
8
- linkColor: joi.string().default('blue'),
9
- borderColor: joi.string().default('black'),
10
- borderThickness: joi.number().default(4)
11
- }).default(),
12
- header: joi.object({
13
- bgColor: joi.string().default('white'),
14
- bgImage: joi.string().optional(),
15
- font: joi.object({
16
- face: joi.string().default('Tahoma'),
17
- bold: joi.boolean().default(true),
18
- color: joi.string().default('black')
19
- }).default()
20
- }).default(),
21
- links: joi.object({
22
- bgColor: joi.string().default('white'),
23
- bgImage: joi.string().optional(),
24
- font: joi.object({
25
- face: joi.string().default('Tahoma'),
26
- bold: joi.boolean.default(true),
27
- color: joi.string().default('black')
28
- }).default()
29
- }),
30
- content: joi.object({
31
- bgColor: joi.string().default('white'),
32
- bgImage: joi.string().optional(),
33
- font: joi.object({
34
- face: joi.string().default('Tahoma'),
35
- bold: joi.boolean.default(false),
36
- color: joi.string().default('black')
37
- }).default()
38
- }).default()
39
- }).default();
40
-
41
- const validated = joi.attempt(theme, schema, {stripUnknown: true});
42
-
43
- return validated;
44
- }
45
-
1
+ const joi = require('joi');
2
+
3
+ function Theme(theme) {
4
+ const schema = joi.object({
5
+ body: joi.object({
6
+ bgColor: joi.string().default('white'),
7
+ bgImage: joi.string().optional(),
8
+ linkColor: joi.string().default('blue'),
9
+ borderColor: joi.string().default('black'),
10
+ borderThickness: joi.number().default(4)
11
+ }).default(),
12
+ header: joi.object({
13
+ bgColor: joi.string().default('white'),
14
+ bgImage: joi.string().optional(),
15
+ font: joi.object({
16
+ face: joi.string().default('Tahoma'),
17
+ bold: joi.boolean().default(true),
18
+ color: joi.string().default('black')
19
+ }).default()
20
+ }).default(),
21
+ links: joi.object({
22
+ bgColor: joi.string().default('white'),
23
+ bgImage: joi.string().optional(),
24
+ font: joi.object({
25
+ face: joi.string().default('Tahoma'),
26
+ bold: joi.boolean.default(true),
27
+ color: joi.string().default('black')
28
+ }).default()
29
+ }),
30
+ content: joi.object({
31
+ bgColor: joi.string().default('white'),
32
+ bgImage: joi.string().optional(),
33
+ font: joi.object({
34
+ face: joi.string().default('Tahoma'),
35
+ bold: joi.boolean.default(false),
36
+ color: joi.string().default('black')
37
+ }).default()
38
+ }).default()
39
+ }).default();
40
+
41
+ const validated = joi.attempt(theme, schema, {stripUnknown: true});
42
+
43
+ return validated;
44
+ }
45
+
46
46
  module.exports = Theme;
package/package.json CHANGED
@@ -1,24 +1,24 @@
1
- {
2
- "name": "legacyweb-pages",
3
- "version": "1.0.7",
4
- "description": "A toolkit for generating legacyweb pages",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "files": [
10
- "images/**",
11
- "lib/**",
12
- "templates/**",
13
- "themes/**",
14
- "index.js"
15
- ],
16
- "author": "Justin Schwartzbeck (justinmschw@gmail.com)",
17
- "license": "ISC",
18
- "dependencies": {
19
- "ejs": "^3.1.8",
20
- "express": "^4.18.2",
21
- "joi": "17.5.0",
22
- "pug": "3.0.2"
23
- }
24
- }
1
+ {
2
+ "name": "legacyweb-pages",
3
+ "version": "1.0.8",
4
+ "description": "A toolkit for generating legacyweb pages",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "files": [
10
+ "images/**",
11
+ "lib/**",
12
+ "templates/**",
13
+ "themes/**",
14
+ "index.js"
15
+ ],
16
+ "author": "Justin Schwartzbeck (justinmschw@gmail.com)",
17
+ "license": "ISC",
18
+ "dependencies": {
19
+ "ejs": "3.1.10",
20
+ "express": "4.19.2",
21
+ "joi": "17.13.3",
22
+ "pug": "3.0.3"
23
+ }
24
+ }
@@ -1,46 +1,46 @@
1
- <html>
2
- <title><%= page.title %></title>
3
- <body bgcolor="<%= body.bgColor %>" <% if (body.bgImage) { %>background="<%- body.bgImage %>"<% } %> link="<%= body.linkColor %>" vlink="<%= body.linkColor %>">
4
-
5
- <table width="780px" border=0>
6
- <tr>
7
- <!-- This is actually where the "border" color is defined -->
8
- <td bgcolor="<%= body.borderColor %>">
9
-
10
- <!-- This inner table is where the page content (header, links, content) actually go
11
- cellspacing = border thickness
12
- -->
13
- <table width="780px" border=0 cellspacing=<%= body.borderThickness %> >
14
- <tr />
15
-
16
- <td height=80px colspan=2 bgcolor="<%= header.bgColor %>" <% if (header.bgImage) { %> background="<%= header.bgImage %>" <% } %>>
17
- <font size=7 face="<%= header.font.face %>" color="<%= header.font.color %>">
18
- <% if (header.font.bold) { %> <b><%- page.header %></b> <% } else { %><%- page.header %><% } %>
19
- </font>
20
- </td>
21
-
22
- <tr />
23
- <td height=600px width=180px bgcolor="<%= links.bgColor %>" <% if (links.bgImage) { %> background="<%= links.bgImage %>" <% } %> valign=top>
24
- <table border="0">
25
- <% page.links.forEach(link => { %>
26
- <tr>
27
- <td <% if (links.bgColor) { %>bgcolor="<%= links.bgColor %>"<% } %>>
28
- <font size=4 face="<%= links.font.face %>">
29
- <% if (links.font.bold) { %><b><a href="<%- link.url %>"><%= link.text %></a></b><% } else { %><a href="<%- link.url %>"><%= link.text %></a><% } %>
30
- </font>
31
- </td>
32
- </tr>
33
- <%})%>
34
- </table>
35
- </td>
36
- <td height=600px width=600px bgcolor="<%= content.bgColor %>" <% if (content.bgImage) { %> background="<%= content.bgImage %>" <% } %> valign=top>
37
- <font face="<%= content.font.face %>">
38
- <%- page.content %>
39
- </font>
40
- </td>
41
- </table>
42
- </td>
43
- </table>
44
-
45
- </body>
1
+ <html>
2
+ <title><%= page.title %></title>
3
+ <body bgcolor="<%= body.bgColor %>" <% if (body.bgImage) { %>background="<%- body.bgImage %>"<% } %> link="<%= body.linkColor %>" vlink="<%= body.linkColor %>">
4
+
5
+ <table width="780px" border=0>
6
+ <tr>
7
+ <!-- This is actually where the "border" color is defined -->
8
+ <td bgcolor="<%= body.borderColor %>">
9
+
10
+ <!-- This inner table is where the page content (header, links, content) actually go
11
+ cellspacing = border thickness
12
+ -->
13
+ <table width="780px" border=0 cellspacing=<%= body.borderThickness %> >
14
+ <tr />
15
+
16
+ <td height=80px colspan=2 bgcolor="<%= header.bgColor %>" <% if (header.bgImage) { %> background="<%= header.bgImage %>" <% } %>>
17
+ <font size=7 face="<%= header.font.face %>" color="<%= header.font.color %>">
18
+ <% if (header.font.bold) { %> <b><%- page.header %></b> <% } else { %><%- page.header %><% } %>
19
+ </font>
20
+ </td>
21
+
22
+ <tr />
23
+ <td height=600px width=180px bgcolor="<%= links.bgColor %>" <% if (links.bgImage) { %> background="<%= links.bgImage %>" <% } %> valign=top>
24
+ <table border="0">
25
+ <% page.links.forEach(link => { %>
26
+ <tr>
27
+ <td <% if (links.bgColor) { %>bgcolor="<%= links.bgColor %>"<% } %>>
28
+ <font size=4 face="<%= links.font.face %>">
29
+ <% if (links.font.bold) { %><b><a href="<%- link.url %>"><%= link.text %></a></b><% } else { %><a href="<%- link.url %>"><%= link.text %></a><% } %>
30
+ </font>
31
+ </td>
32
+ </tr>
33
+ <%})%>
34
+ </table>
35
+ </td>
36
+ <td height=600px width=600px bgcolor="<%= content.bgColor %>" <% if (content.bgImage) { %> background="<%= content.bgImage %>" <% } %> valign=top>
37
+ <font face="<%= content.font.face %>">
38
+ <%- page.content %>
39
+ </font>
40
+ </td>
41
+ </table>
42
+ </td>
43
+ </table>
44
+
45
+ </body>
46
46
  </html>
@@ -1,39 +1,39 @@
1
- <html>
2
- <title><%= page.title %></title>
3
- <body bgcolor="<%= body.bgColor %>" <% if (body.bgImage) { %>background="<%- body.bgImage %>"<% } %> link="<%= body.linkColor %>" vlink="<%= body.linkColor %>">
4
- <center>
5
- <table width="786px" border=0>
6
- <tr>
7
- <!-- This is actually where the "border" color is defined -->
8
- <td bgcolor="<%= body.borderColor %>">
9
-
10
- <!-- This inner table is where the page content (header, links, content) actually go
11
- cellspacing = border thickness
12
- -->
13
- <table width="780px" border=0 cellspacing=<%= body.borderThickness %> >
14
- <tr />
15
-
16
- <td height=80px bgcolor="<%= header.bgColor %>" <% if (header.bgImage) { %> background="<%= header.bgImage %>" <% } %>>
17
- <font size=7 face="<%= header.font.face %>" color="<%= header.font.color %>">
18
- <% if (header.font.bold) { %> <b><%- page.header %></b> <% } else { %><%- page.header %><% } %>
19
- </font>
20
- </td>
21
-
22
- <tr>
23
- <td height=20px bgcolor="<%= links.bgColor %>" <% if (links.bgImage) { %> background="<%= links.bgImage %>" <% } %> valign=top>
24
- <%- page.strip %>
25
- </td>
26
- </tr>
27
- <tr />
28
-
29
- <td bgcolor="<%= content.bgColor %>" <% if (content.bgImage) { %> background="<%= content.bgImage %>" <% } %> valign=top>
30
- <font face="<%= content.font.face %>">
31
- <%- page.content %>
32
- </font>
33
- </td>
34
- </table>
35
- </td>
36
- </table>
37
- </center>
38
- </body>
1
+ <html>
2
+ <title><%= page.title %></title>
3
+ <body bgcolor="<%= body.bgColor %>" <% if (body.bgImage) { %>background="<%- body.bgImage %>"<% } %> link="<%= body.linkColor %>" vlink="<%= body.linkColor %>">
4
+ <center>
5
+ <table width="786px" border=0>
6
+ <tr>
7
+ <!-- This is actually where the "border" color is defined -->
8
+ <td bgcolor="<%= body.borderColor %>">
9
+
10
+ <!-- This inner table is where the page content (header, links, content) actually go
11
+ cellspacing = border thickness
12
+ -->
13
+ <table width="780px" border=0 cellspacing=<%= body.borderThickness %> >
14
+ <tr />
15
+
16
+ <td height=80px bgcolor="<%= header.bgColor %>" <% if (header.bgImage) { %> background="<%= header.bgImage %>" <% } %>>
17
+ <font size=7 face="<%= header.font.face %>" color="<%= header.font.color %>">
18
+ <% if (header.font.bold) { %> <b><%- page.header %></b> <% } else { %><%- page.header %><% } %>
19
+ </font>
20
+ </td>
21
+
22
+ <tr>
23
+ <td height=20px bgcolor="<%= links.bgColor %>" <% if (links.bgImage) { %> background="<%= links.bgImage %>" <% } %> valign=top>
24
+ <%- page.strip %>
25
+ </td>
26
+ </tr>
27
+ <tr />
28
+
29
+ <td bgcolor="<%= content.bgColor %>" <% if (content.bgImage) { %> background="<%= content.bgImage %>" <% } %> valign=top>
30
+ <font face="<%= content.font.face %>">
31
+ <%- page.content %>
32
+ </font>
33
+ </td>
34
+ </table>
35
+ </td>
36
+ </table>
37
+ </center>
38
+ </body>
39
39
  </html>
@@ -1,28 +1,28 @@
1
- {
2
- "body": {
3
- "bgColor": "#00008B",
4
- "linkColor": "blue",
5
- "borderColor": "black",
6
- "borderThickness": 4
7
- },
8
- "header": {
9
- "bgColor": "#808080",
10
- "font": {
11
- "face": "Courier New",
12
- "bold": true
13
- }
14
- },
15
- "links": {
16
- "bgColor": "#D3D3D3",
17
- "font": {
18
- "face": "Tahoma",
19
- "bold": true
20
- }
21
- },
22
- "content": {
23
- "bgColor": "#FFFFFF",
24
- "font": {
25
- "face": "Tahoma"
26
- }
27
- }
1
+ {
2
+ "body": {
3
+ "bgColor": "#00008B",
4
+ "linkColor": "blue",
5
+ "borderColor": "black",
6
+ "borderThickness": 4
7
+ },
8
+ "header": {
9
+ "bgColor": "#808080",
10
+ "font": {
11
+ "face": "Courier New",
12
+ "bold": true
13
+ }
14
+ },
15
+ "links": {
16
+ "bgColor": "#D3D3D3",
17
+ "font": {
18
+ "face": "Tahoma",
19
+ "bold": true
20
+ }
21
+ },
22
+ "content": {
23
+ "bgColor": "#FFFFFF",
24
+ "font": {
25
+ "face": "Tahoma"
26
+ }
27
+ }
28
28
  }