From 84d20810724608c3cb81b59c7b9f728b873dd81c Mon Sep 17 00:00:00 2001 From: David Ball Date: Mon, 3 Jun 2024 12:55:21 -0400 Subject: [PATCH] Added PUBLIC_DIR environment variable. --- .env.example | 3 +++ app/server.js | 9 ++++----- gulpfile.js | 25 ++++++++++++++++++++++--- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/.env.example b/.env.example index c874a067..e779af67 100644 --- a/.env.example +++ b/.env.example @@ -40,3 +40,6 @@ TIKA_HOST="tika" TIKA_PORT=9998 # TIKA_URL is the URL to access the host running Apache Tika. TIKA_URL="http://${TIKA_HOST}:${TIKA_PORT}" + +# PUBLIC_DIR is the directory relative to this project root for the public files +PUBLIC_DIR="../nm3clol-public" diff --git a/app/server.js b/app/server.js index aa865ac5..4a0d264d 100644 --- a/app/server.js +++ b/app/server.js @@ -14,6 +14,7 @@ const dotenvExpand = require('dotenv-expand'); dotenv.config(); dotenvExpand.expand(process.env); // const advancedSearch = require('../routes/advanced-search'); +const publicPath = path.join(__dirname, '..', process.env.PUBLIC_DIR.replaceAll('\\', path.sep).replaceAll('/', path.sep)); // Port number for HTTP server const port = process.env.PORT||3000; @@ -240,16 +241,14 @@ app.get('/svg/*.svg', async (req, res) => { console.log(`Setting route for *`); app.get('*', async (req, res) => { await serve(req, res, { - public: path.join(__dirname, '..', 'public'), + public: publicPath, symlinks: true, trailingSlash: true, cleanUrls: false, renderSingle: false, unlisted: [ - ".DS_Store", - ".git", - "Thumbs.db", - "README*", + ".*", //dot files/folders + "Thumbs.db" ], redirects: [ { diff --git a/gulpfile.js b/gulpfile.js index a34c9390..164fe933 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -13,7 +13,7 @@ const dotenvExpand = require('dotenv-expand'); dotenv.config(); dotenvExpand.expand(process.env); -const relPathToFiles = './public'; +const publicPath = path.join(__dirname, '..', process.env.PUBLIC_DIR.replaceAll('\\', path.sep).replaceAll('/', path.sep)); const defaultSiteUrl = 'http://localhost'; const defaultTikaUrl = 'http://tika:9998'; @@ -169,7 +169,7 @@ gulp.task('index:laws', async () => { ]; // Use glob to match files in the local directories let files = []; - let cwd = path.resolve(__dirname, relPathToFiles.replaceAll('/', path.sep)); + let cwd = path.resolve(__dirname, publicPath.replaceAll('/', path.sep)); globs.forEach(async (globPattern) => { files = files.concat(glob.globSync(globPattern, { cwd, @@ -268,7 +268,7 @@ gulp.task('index:docs', async () => { ]; // Use glob to match files in the local directories let files = []; - let cwd = path.resolve(__dirname, relPathToFiles.replaceAll('/', path.sep)); + let cwd = path.resolve(__dirname, publicPath.replaceAll('/', path.sep)); globs.forEach(async (globPattern) => { files = files.concat(glob.globSync(globPattern, { cwd, @@ -358,6 +358,15 @@ gulp.task('index:docs', async () => { // Add additional fields as needed (e.g., title, author, etc.) }; + // Save a copy of the text into a file + fs.writeFileSync(fileFullPath + ".tika.g.txt", extractedText, (err) => { + if (err) { + console.error('Error writing to file', err); + } else { + console.log(`File ${fileName} has been written successfully!`); + } + }); + // Send document to Solr for indexing // Index the file with its text content and metadata console.log(`Indexing ${url}`); @@ -366,6 +375,16 @@ gulp.task('index:docs', async () => { // Continue console.log(`Done.`); } else { + console.log('metadata:', metadata); + // Save a copy of the text into a file + fs.writeFileSync(fileFullPath + ".tika.g.txt", extractedText, (err) => { + if (err) { + console.error('Error writing to file', err); + } else { + console.log(`File ${fileName} has been written successfully!`); + } + }); + // Metadata matches, skip the file console.log(`Skipping file '${file}' as metadata matches existing metadata in Solr index.`); }