diff --git a/app.js b/app.js index 4db318f..0249912 100644 --- a/app.js +++ b/app.js @@ -9,7 +9,13 @@ const publicPath = "/public" const inUrlPath = "public" -app.engine('.hbs', engine({extname: '.hbs'})); +app.engine('.hbs', engine({extname: '.hbs', helpers: { + ifDivisibleBy: function (index, divisor, options) { + if (index % divisor === 0) { + return options.fn(this); + } + } +}})); app.set('view engine', '.hbs'); app.use(publicPath, express.static(inUrlPath), serveIndex(inUrlPath, { diff --git a/public/styles/home/home.css b/public/styles/home/index.css similarity index 100% rename from public/styles/home/home.css rename to public/styles/home/index.css diff --git a/public/styles/lists/sites/index.css b/public/styles/lists/sites/index.css new file mode 100644 index 0000000..27cf8ea --- /dev/null +++ b/public/styles/lists/sites/index.css @@ -0,0 +1,4 @@ +.archive{ + font-size: 11px; + text-decoration: none; +} \ No newline at end of file diff --git a/public/styles/main.css b/public/styles/main.css index 77ce5c6..5bf4de2 100644 --- a/public/styles/main.css +++ b/public/styles/main.css @@ -1,21 +1,29 @@ +:root{ + --celeste: #20d6c7; +} + body{ margin: 0; padding: 0; background-color: black; - color: #20d6c7; + color: var(--celeste); font-family: "Junicode"; image-rendering: pixelated; } p{ - color: white + color: white; +} + +a{ + color: var(--celeste); } hr{ display: block; height: 1px; border: 0; - border-top: 1px solid #20d6c7; + border-top: 1px solid var(--celeste); margin: 1em 0; padding: 0; } \ No newline at end of file diff --git a/src/router/indexRouter.js b/src/router/indexRouter.js index 7f6bf5f..bb65422 100644 --- a/src/router/indexRouter.js +++ b/src/router/indexRouter.js @@ -1,23 +1,54 @@ -const express = require('express'); const createCommonPath = require('../utils/createCommonPath'); +const express = require('express'); const router = express.Router(); const { readCsv } = require('../utils/csv'); const { dirname } = require('path'); const appDir = dirname(require.main.filename); -createCommonPath(router, '/', "home", { - stylesheet: '/public/styles/home/home.css' -}) +createCommonPath(router, '/', {view: "home"}) -router.get('/lists/anime', async (_req, res) => { +createCommonPath(router, 'lists/anime', {title: "Anime List"}, async (req, res) => { try{ const animeList = await readCsv(appDir + '/public/dynamic/sync/media_list/anime.csv') const vnList = await readCsv(appDir + '/public/dynamic/sync/media_list/vn_vidya.csv') - res.render('lists/anime', { + return { animeList, - vnList, - title: "Anime List" - }) + vnList + } + } + catch(err){ + console.error(err) + res.send("Mistakes were made") + } +}) + +createCommonPath(router, 'lists/sites', {title: "Site List"}, async (_req, res) => { + try{ + const siteList = await readCsv(appDir + '/public/dynamic/sync/sites.csv') + const categoryList = await readCsv(appDir + '/public/dynamic/sync/sites_category.csv') + + const categoriesAndSites = {} + + for(i in siteList){ + const site = siteList[i] + for (j in categoryList){ + const cat = categoryList[j] + if (cat.id === site.id_category){ + if (!categoriesAndSites.hasOwnProperty(cat.name)) categoriesAndSites[cat.name] = { + ...cat, + sites: [site] + } + else{ + categoriesAndSites[cat.name].sites.push(site) + } + break + } + } + } + + return { + categoriesAndSites + } } catch(err){ console.error(err) diff --git a/src/utils/createCommonPath.js b/src/utils/createCommonPath.js index 829b23e..2e11daf 100644 --- a/src/utils/createCommonPath.js +++ b/src/utils/createCommonPath.js @@ -1,6 +1,17 @@ -function createCommonPath(router, path, view = path, render_parameters = {}){ - router.get(path, (req, res) => { - res.render(view, render_parameters) +function createCommonPath(router, path, renderParams = { +}, cb = () => {}){ + router.get('/' + path, async (req, res) => { + const defaultParams = { + view: path, + } + const split_path = defaultParams.view.split('/') + const default_name = split_path[split_path.length-1] + defaultParams.name = default_name + defaultParams.stylesheet = !renderParams.view ? '/public/styles/' + defaultParams.view + '/index' + '.css' : '/public/styles/' + renderParams.view + '/index' + '.css' + let renderOptions = {...defaultParams, ...renderParams} + const cb_params = await cb(req, res) + renderOptions = {...renderOptions, ...cb_params} + res.render(renderOptions.view, renderOptions) }) } diff --git a/views/home.hbs b/views/home.hbs index 9599439..628870a 100644 --- a/views/home.hbs +++ b/views/home.hbs @@ -34,7 +34,7 @@

Cut the umbilical cord.

Back to the holy land.

-
+

CC files

YuugenMagan

diff --git a/views/lists/sites.hbs b/views/lists/sites.hbs new file mode 100644 index 0000000..199cd29 --- /dev/null +++ b/views/lists/sites.hbs @@ -0,0 +1,29 @@ + +
+ + {{#each categoriesAndSites}} + {{#ifDivisibleBy @index 2}} + + + {{/ifDivisibleBy}} + + + {{/each}} +
+

{{name}}

+
    + {{#each sites}} +
  • + {{name}} [archive] + {{#if image}} +
    + + {{/if}} + {{#if description}} + {{description}} + {{/if}} +
  • + {{/each}} +
+
+ \ No newline at end of file