From 23b9005fc2344e6fe7a9f8ef9620028f7032e96e Mon Sep 17 00:00:00 2001 From: bill bittner Date: Fri, 9 Jun 2017 16:46:57 -0700 Subject: [PATCH] converted to handlebars --- helpers/routeHelpers.js | 2 +- package.json | 1 + public/assets/css/style.css | 3 + public/fourOhfour.html | 14 -- public/index.html | 196 ------------------ public/noClaims.html | 14 -- routes/html-routes.js | 8 +- server.js | 10 +- views/allClaims.handlebars | 12 ++ views/fourOhFour.handlebars | 3 + views/index.handlebars | 100 +++++++++ .../layouts/main.handlebars | 7 +- views/noClaims.handlebars | 4 + views/partials/bugs.handlebars | 7 + views/partials/contribute.handlebars | 4 + views/partials/documentation.handlebars | 39 ++++ views/partials/examples.handlebars | 10 + views/partials/links.handlebars | 6 + views/partials/publish.handlebars | 22 ++ 19 files changed, 226 insertions(+), 236 deletions(-) delete mode 100644 public/fourOhfour.html delete mode 100644 public/index.html delete mode 100644 public/noClaims.html create mode 100644 views/allClaims.handlebars create mode 100644 views/fourOhFour.handlebars create mode 100644 views/index.handlebars rename public/invalidUri.html => views/layouts/main.handlebars (67%) create mode 100644 views/noClaims.handlebars create mode 100644 views/partials/bugs.handlebars create mode 100644 views/partials/contribute.handlebars create mode 100644 views/partials/documentation.handlebars create mode 100644 views/partials/examples.handlebars create mode 100644 views/partials/links.handlebars create mode 100644 views/partials/publish.handlebars diff --git a/helpers/routeHelpers.js b/helpers/routeHelpers.js index 6aa294c4..f3f43814 100644 --- a/helpers/routeHelpers.js +++ b/helpers/routeHelpers.js @@ -3,7 +3,7 @@ var path = require('path'); module.exports = { handleRequestError: function(error, res) { if ((error === "NO_CLAIMS") || (error === "NO_FREE_PUBLIC_CLAIMS")){ - res.status(307).sendFile(path.join(__dirname, '../public', 'noClaims.html')); + res.status(307).render('noClaims'); } else if (error.response){ res.status(error.response.status).send(error.response.data.error.message); } else if (error.code === "ECONNREFUSED") { diff --git a/package.json b/package.json index 2300bd02..799ceade 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "axios": "^0.16.1", "body-parser": "^1.17.1", "express": "^4.15.2", + "express-handlebars": "^3.0.0", "nodemon": "^1.11.0", "socket.io": "^2.0.1", "socketio-file-upload": "^0.6.0" diff --git a/public/assets/css/style.css b/public/assets/css/style.css index e69de29b..88ef37b6 100644 --- a/public/assets/css/style.css +++ b/public/assets/css/style.css @@ -0,0 +1,3 @@ +.all-claims-img { + height: 200px; +} \ No newline at end of file diff --git a/public/fourOhfour.html b/public/fourOhfour.html deleted file mode 100644 index 982f8678..00000000 --- a/public/fourOhfour.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - Four Oh Four - - -

spee.ch

-

404: Not Found

-

That page does not exist. Return home.

- - \ No newline at end of file diff --git a/public/index.html b/public/index.html deleted file mode 100644 index 71e0c3f0..00000000 --- a/public/index.html +++ /dev/null @@ -1,196 +0,0 @@ - - - - - - - Spee.ch - - - -

spee.ch

-

spee.ch is a single-serving site that reads and publishes images to and from the LBRY blockchain.

-
-

Examples:

- -
-
-

Publish Your Own

-
-
- -
- Image preview... -
- Name: -
- License: -
- NSFW: -

By clicking 'Publish' I attest that I have read and agree to the LBRY terms of service.

- -
-
-
-
-

Help Wanted!

-

If you would like to help make spee.ch amazing, join our slack channel.

-

We are currently in need of a designer to help with styling spee.ch's front end, but all help is welcome!

-
-
-

Documentation

-

Site Navigation

- -

API

-

Note: these are being used for testing durring spee.ch development and may not be maintained

- -
-
-

Links

- github - lbry - slack -
-
-

Bugs

-

Spee.ch is young and under continuous development so it will have bugs. Please leave an issue on our github if you experience a problem or have suggestions.

-
 .w. -
(o|o) -
  `'` -
- - - - - diff --git a/public/noClaims.html b/public/noClaims.html deleted file mode 100644 index 5ec22a47..00000000 --- a/public/noClaims.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - No Claims - - -

spee.ch

-

No Claims

-

There are no free, public images at that claim. You should publish one at spee.ch.

- - \ No newline at end of file diff --git a/routes/html-routes.js b/routes/html-routes.js index 433a3bdc..dc6e2fb3 100644 --- a/routes/html-routes.js +++ b/routes/html-routes.js @@ -14,8 +14,8 @@ module.exports = function(app){ // create promise lbryApi.getAllClaims(req.params.name) .then(function(orderedFreePublicClaims){ - console.log("/:name/all success.") - res.status(200).send(orderedFreePublicClaims); + console.log("/:name/all success."); + res.status(200).render('allClaims', { claims: orderedFreePublicClaims }); return; }) .catch(function(error){ @@ -53,10 +53,10 @@ module.exports = function(app){ }); // route for the home page app.get("/", function(req, res){ - res.status(200).sendFile(path.join(__dirname, '../public', 'index.html')); + res.status(200).render('index'); }); // a catch-all route if someone visits a page that does not exist app.use("*", function(req, res){ - res.status(404).sendFile(path.join(__dirname, '../public', 'fourOhfour.html')); + res.status(404).render('fourOhFour'); }); } diff --git a/server.js b/server.js index abf98fba..63601032 100644 --- a/server.js +++ b/server.js @@ -3,6 +3,7 @@ var express = require('express'); var bodyParser = require('body-parser'); var path = require('path'); var siofu = require("socketio-file-upload"); +var expressHandlebars = require("express-handlebars"); // set port var PORT = 3000; @@ -14,16 +15,19 @@ var app = express(); app.use(express.static(__dirname + '/public')); // configure express app -app.use(bodyParser.json()); // for parsing application/json +app.use(bodyParser.json()); // for parsing application/json app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded app.use(siofu.router); +// configure handlebars +app.engine('handlebars', expressHandlebars({defaultLayout: 'main'})); +app.set('view engine', 'handlebars'); + // require express routes require("./routes/api-routes.js")(app); require("./routes/html-routes.js")(app); -// include socket.io functionality -// this wraps the server in sockets, to intercept incoming sockets requests +// wrap the server in socket.io to intercept incoming sockets requests var http = require("./routes/sockets-routes.js")(app); // start server diff --git a/views/allClaims.handlebars b/views/allClaims.handlebars new file mode 100644 index 00000000..eb5b2adc --- /dev/null +++ b/views/allClaims.handlebars @@ -0,0 +1,12 @@ +

All Claims

+

These are all the free, public assets at that claim. You can publish more at spee.ch.

+ +{{#each claims}} +
+ +

claim_id: {{this.claim_id}}

+

direct link here

+

author: {{this.value.stream.metadata.author}}

+

description: {{this.value.stream.metadata.description}}

+

license: {{this.value.stream.metadata.license}}

+{{/each}} diff --git a/views/fourOhFour.handlebars b/views/fourOhFour.handlebars new file mode 100644 index 00000000..587389d7 --- /dev/null +++ b/views/fourOhFour.handlebars @@ -0,0 +1,3 @@ +

spee.ch

+

404: Not Found

+

That page does not exist. Return home.

\ No newline at end of file diff --git a/views/index.handlebars b/views/index.handlebars new file mode 100644 index 00000000..3d829ea5 --- /dev/null +++ b/views/index.handlebars @@ -0,0 +1,100 @@ +

spee.ch

+

spee.ch is a single-serving site that reads and publishes images to and from the LBRY blockchain.

+ +{{> examples}} +{{> publish}} +{{> links}} +{{> documentation}} +{{> bugs}} +{{> contribute}} + + + + diff --git a/public/invalidUri.html b/views/layouts/main.handlebars similarity index 67% rename from public/invalidUri.html rename to views/layouts/main.handlebars index a4b0673e..03760135 100644 --- a/public/invalidUri.html +++ b/views/layouts/main.handlebars @@ -4,11 +4,10 @@ - No Claims + + Spee.ch -

spee.ch

-

Invalid URI

-

There is no claim at that URI.

+ {{{ body }}} \ No newline at end of file diff --git a/views/noClaims.handlebars b/views/noClaims.handlebars new file mode 100644 index 00000000..70c979fe --- /dev/null +++ b/views/noClaims.handlebars @@ -0,0 +1,4 @@ +

spee.ch

+

No Claims

+

There are no free, public images at that claim. You should publish one at spee.ch.

+

NOTE: it is possible your claim was published, but it is still being processed by the blockchain

\ No newline at end of file diff --git a/views/partials/bugs.handlebars b/views/partials/bugs.handlebars new file mode 100644 index 00000000..d5b90b66 --- /dev/null +++ b/views/partials/bugs.handlebars @@ -0,0 +1,7 @@ +
+

Bugs

+

Spee.ch is young and under continuous development so it will have bugs. Please leave an issue on our github if you experience a problem or have suggestions.

+
 .w. +
(o|o) +
  `'` +
\ No newline at end of file diff --git a/views/partials/contribute.handlebars b/views/partials/contribute.handlebars new file mode 100644 index 00000000..bc22b36b --- /dev/null +++ b/views/partials/contribute.handlebars @@ -0,0 +1,4 @@ +
+

Contribute

+

If you would like to help make spee.ch amazing, join our slack channel!

+
\ No newline at end of file diff --git a/views/partials/documentation.handlebars b/views/partials/documentation.handlebars new file mode 100644 index 00000000..75291fd2 --- /dev/null +++ b/views/partials/documentation.handlebars @@ -0,0 +1,39 @@ +
+

Documentation

+

Site Navigation

+ +

API

+

Note: these are being used for testing durring spee.ch development and may not be maintained

+ +
\ No newline at end of file diff --git a/views/partials/examples.handlebars b/views/partials/examples.handlebars new file mode 100644 index 00000000..6f88ef2a --- /dev/null +++ b/views/partials/examples.handlebars @@ -0,0 +1,10 @@ +
+

Examples:

+ +
\ No newline at end of file diff --git a/views/partials/links.handlebars b/views/partials/links.handlebars new file mode 100644 index 00000000..d127b327 --- /dev/null +++ b/views/partials/links.handlebars @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/views/partials/publish.handlebars b/views/partials/publish.handlebars new file mode 100644 index 00000000..d7385282 --- /dev/null +++ b/views/partials/publish.handlebars @@ -0,0 +1,22 @@ +
+

Publish Your Own

+
+ +
+ Image preview... +
+ Name: +
+ License: +
+ NSFW: +

By clicking 'Publish' I attest that I have read and agree to the LBRY terms of service.

+ +
+
\ No newline at end of file -- 2.45.2