summaryrefslogtreecommitdiff
path: root/load_spreadsheet.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2021-09-03 15:25:32 +0200
committerJules Laplace <julescarbon@gmail.com>2021-09-03 15:25:32 +0200
commitf2c4d48523a8a6d541289e2d4c57a65eeb9f5af0 (patch)
tree9a8ed86a75b9bb7a85e9431c0d074431bded0d99 /load_spreadsheet.js
parent5fffdeb831a7fdc6a8e4c58c7d477dc4af78ec68 (diff)
displaying videos
Diffstat (limited to 'load_spreadsheet.js')
-rw-r--r--load_spreadsheet.js65
1 files changed, 50 insertions, 15 deletions
diff --git a/load_spreadsheet.js b/load_spreadsheet.js
index 7c06477..5f50fa5 100644
--- a/load_spreadsheet.js
+++ b/load_spreadsheet.js
@@ -15,11 +15,13 @@ var tagTypes = "No6092,1620s,painting,blunt,National Gallery of Canada,AGO,court
","
);
+/**
+ * Load the spreadsheet and RTF files in subdirectories, building the db.json
+ */
async function main() {
- // basically this script exists to assign the X'd fields from the spreadsheet
- // to the okcms json :)
const data = await loadCSV(datasheetFile);
- const db = await loadJSON(dbFile);
+ // const db = await loadJSON(dbFile);
+ const db = {};
const dataStore = await loadDataStoreIndex("./data_store");
db.page = db.page || [];
@@ -64,9 +66,13 @@ async function main() {
}
}
+ console.log("Done");
await writeJSON(dbFile, db);
}
+/**
+ * Load the list of folders from the data_store
+ */
async function loadDataStoreIndex(path) {
const files = await readdir(path);
let parts, index;
@@ -81,6 +87,9 @@ async function loadDataStoreIndex(path) {
return folders;
}
+/**
+ * Load the files from a particular exhibit from their subdirectory in data_store
+ */
async function loadFiles(folder, record) {
const path = `./data_store/${folder}/`;
const files = await readdir(path);
@@ -94,6 +103,10 @@ async function loadFiles(folder, record) {
await loadText(path + file, record);
} else if (file.match(/.txt/i)) {
console.error("+ fix text file", path + file);
+ } else if (file.match(/.mtl/i)) {
+ console.error("+ load mtl", path + file);
+ } else if (file.match(/.obj/i)) {
+ console.error("+ load mtl", path + file);
} else if (file.match(/-thumb/i)) {
dimensions = sizeOf(path + file);
record.thumbnail = {
@@ -112,9 +125,15 @@ async function loadFiles(folder, record) {
}
}
+/**
+ * Load the text from an RTF
+ */
async function loadText(path, record) {
+ // const warn = path.match("McCurry", "i");
return new Promise((resolve, reject) => {
parseRTF.stream(fs.createReadStream(path), (err, doc) => {
+ // Separate paragraphs from spans since this library doesn't handle
+ // the last paragraph correctly.
const paragraphs = doc.content.filter((para) => para.content);
const finalParagraph = doc.content.filter((para) => !para.content);
record.citation = "";
@@ -123,6 +142,7 @@ async function loadText(path, record) {
let content = "";
record.author = "";
record.title = "";
+
paragraphs.forEach((para, paragraphIndex) => {
const paragraph = [];
para.content.forEach((clip) => {
@@ -153,6 +173,10 @@ async function loadText(path, record) {
groupCount += 1;
}
});
+
+ record.title = record.title.replace(/<\/i><i>/g, "");
+
+ // The last paragraph is just spans for some reason
const finalParagraphExtract = [];
finalParagraph.forEach((clip) => {
appendClip(finalParagraphExtract, clip);
@@ -167,19 +191,27 @@ async function loadText(path, record) {
});
}
+/**
+ * Append a clip to a paragraph, adding formating (i.e. italics)
+ */
function appendClip(paragraph, clip) {
paragraph.push(getClipValue(clip));
}
function getClipValue(clip) {
+ let value = clip.value;
if (clip.style.italic) {
- return "<i>" + clip.value + "</i>";
+ value = "<i>" + value + "</i>";
+ } else if (clip.style.bold) {
+ value = "<b>" + value + "</b>";
} else if (clip.style.underline) {
- return "<u>" + clip.value + "</u>";
- } else {
- return clip.value;
+ value = "<u>" + value + "</u>";
}
+ return value;
}
+/**
+ * Load the video link from those RTF files
+ */
async function loadLink(path, record) {
return new Promise((resolve, reject) => {
parseRTF.stream(fs.createReadStream(path), (err, doc) => {
@@ -196,20 +228,20 @@ async function loadLink(path, record) {
uri = para.value.trim();
}
});
- let match = uri.match(/\d+/);
- let token = "";
- if (match) {
- token = match[0];
- } else {
- console.error("No token:", uri);
- }
+ // let match = uri.match(/\d+/);
+ // let token = "";
+ // if (match) {
+ // token = match[0];
+ // } else {
+ // console.error("No token:", uri);
+ // }
record.type = "video";
record.images = [
{
type: "video",
caption: "",
uri,
- token,
+ // token,
},
];
resolve();
@@ -217,4 +249,7 @@ async function loadLink(path, record) {
});
}
+/**
+ * Load everything and then exit!
+ */
main().then(() => process.exit(0));