diff --git a/app/server.js b/app/server.js index 039b72c0..52071f48 100644 --- a/app/server.js +++ b/app/server.js @@ -35,12 +35,14 @@ app.use(express.json()); // res.send('Hello World!'); // }) +console.log("Setting route for /ads.txt"); app.get('/ads.txt', (req, res) => { res.setHeader("Content-Type", "text/plain"); res.setHeader("Cache-Control", "no-cache"); res.send(`google.com, pub-8937572456576531, DIRECT, f08c47fec0942fa0`); }); +console.log("Setting route for /robots.txt"); app.get('/robots.txt', (req, res) => { res.setHeader("Content-Type", "text/plain"); res.setHeader("Cache-Control", "no-cache"); @@ -55,10 +57,12 @@ Allow: / }); // Search endpoints +console.log("Setting route for /search"); app.use('/search', search.router); // app.use('/advanced-search', advancedSearch.router); // Endpoints for all the site's pages. +console.log("Scanning for pages to create routes"); glob.globSync('pages/**/*.md', { cwd: path.join(__dirname, '..'), matchBase: true, @@ -71,6 +75,7 @@ glob.globSync('pages/**/*.md', { const fullFilePath = path.join(__dirname, '..', filePath); let paths = route.split(path.posix.sep); paths[0] = 'public'; + console.log(`Setting route for ${route}`); app.get(route, async (req, res) => { const fm = matter.read(fullFilePath); const fmData = { fm: fm.data, excerpt: fm.excerpt }; @@ -80,8 +85,46 @@ glob.globSync('pages/**/*.md', { }); }); +// Endpoints for all the site's YouTube videos. +console.log("Scanning for archived videos to create routes"); +glob.globSync('Russell_County/Board_of_Supervisors/YouTube_Archive/**/*.info.json', { + cwd: path.join(__dirname, '..', 'public'), + matchBase: true, + follow: true, +}).forEach((filePath) => { + const expressRoutePathFromFilePath = (filePath) => { + return path.posix.sep+filePath.substring(0, filePath.lastIndexOf(path.sep)).replaceAll(path.sep, path.posix.sep); + }; + const dirFromFilePath = (filePath) => { + return filePath.substring(0, filePath.lastIndexOf(path.sep)); + } + const directory = dirFromFilePath(filePath); + let videoURL = glob.globSync("*.{mpg,mpeg,mp4,mkv,webm}", { + cwd: path.join(__dirname, '..', 'public', directory), + matchBase: true, + follow: true, + }).pop(); + const route = encodeURI(expressRoutePathFromFilePath(filePath)); + let paths = filePath.substring(0, filePath.lastIndexOf(path.sep) > 0 ? filePath.lastIndexOf(path.sep) : filePath.length-1).split(path.sep); + paths = paths.map((name, idx, aPaths) => { + let url = aPaths.slice(0, idx+1).join(path.posix.sep); + return { + name, + url, + }; + }); + const fullFilePath = path.join(__dirname, '..', 'public', filePath); + console.log(`Setting route for ${route}`); + app.get(route, async (req, res) => { + let info = require(fullFilePath); + const renderData = { route, filePath, fullFilePath, req, paths, directory, videoURL, info }; + res.render("video-player", { h: helpers, ...renderData }); + }); +}); + //app.get('/OCR-Encoded-PDFs/Russell-County-Web-Site_2024-02-13_19_50_Modified-With-OCR-Encoding**', rewriter.rewrite('/Web_Site_Archives/Russell_County_Web_Site-2024-02-13_19_50_Modified_With_OCR_Encoding/$1')); +console.log(`Setting route for *`); app.get('*', async (req, res) => { await serve(req, res, { public: path.join(__dirname, '..', 'public'), diff --git a/views/helpers/functions.js b/views/helpers/functions.js index 3d7d8bd6..a66fc850 100644 --- a/views/helpers/functions.js +++ b/views/helpers/functions.js @@ -1,4 +1,5 @@ const path = require('path'); +const glob = require('glob'); const fs = require('fs'); const process = require('process'); const markdownit = require('markdown-it'); diff --git a/views/video-player.ejs b/views/video-player.ejs new file mode 100644 index 00000000..d3e07865 --- /dev/null +++ b/views/video-player.ejs @@ -0,0 +1,53 @@ + + +
+