From f66c0b86738573a12861178646b2546557ce81f0 Mon Sep 17 00:00:00 2001 From: David Ball Date: Mon, 24 Jun 2024 02:10:18 -0400 Subject: [PATCH] feat: Default tab automatically loads viewer, but other tabs are lazily loaded. OCR text moved to its own tab. --- app/helpers/functions.mts | 10 ++++ app/views/directory.ejs | 118 +++++++++++++++++++++++--------------- 2 files changed, 82 insertions(+), 46 deletions(-) diff --git a/app/helpers/functions.mts b/app/helpers/functions.mts index 5c6e2000..32601299 100644 --- a/app/helpers/functions.mts +++ b/app/helpers/functions.mts @@ -194,6 +194,15 @@ const isGoogleDocsViewerSupported = (file: string) => { return isMsOfficeViewerSupported(file) || path.extname(file).search(/^((?:.pdf))$/ig) != -1; } +const defaultViewerForFile = (file: string) => { + if (isMsOfficeViewerSupported(file)) { + return "ms-office-viewer"; + } + else if (path.extname(file).search(/^((?:.pdf))$/ig) != -1) { + return "built-in"; + } +} + export default { leftTrimFirstDirectory, trimSlashes, @@ -215,4 +224,5 @@ export default { moment, isMsOfficeViewerSupported, isGoogleDocsViewerSupported, + defaultViewerForFile, }; \ No newline at end of file diff --git a/app/views/directory.ejs b/app/views/directory.ejs index 76aef4ed..3c911eae 100644 --- a/app/views/directory.ejs +++ b/app/views/directory.ejs @@ -31,79 +31,105 @@
<% if (h.isMsOfficeViewerSupported(h.readmeFm(directory).file)) { %> -
- +
+
+ <% if (h.defaultViewerForFile(h.readmeFm(directory).file) != 'ms-office-viewer') { %> + + <% } %> <% } %> <% if (h.isGoogleDocsViewerSupported(h.readmeFm(directory).file)) { %> -
- +
+
+ <% if (h.defaultViewerForFile(h.readmeFm(directory).file) != 'google-docs-viewer') { %> + + <% } %> <% } %> -
- +
+
- - <% if (!h.isMsOfficeViewerSupported(h.readmeFm(directory).file) && !h.isGoogleDocsViewerSupported(h.readmeFm(directory).file)) { %> + <% if (h.defaultViewerForFile(h.readmeFm(directory).file) != 'built-in') { %> <% } %> +
+
+
+

OCR Scan (approximately)

+

+ This OCR scan may contain automatically generated text as generated using Apache Tika + and Tesseract. It may not be correct. No effort has been made to correct any of these scans + (so far). These OCR scans are also used in the site's Search feature. Please review the + Search Policy for details about the site features. + The OCR scan is provided here for reference purposes. It provides searchable text when the + underlying document might not. But the scan process may not always work perfectly. +

+
<%- h.printReadme(directory) %>
+
+
+
<% } else { %> <%- h.printReadme(directory) %> <% } %>
- <% if (typeof h.readmeFm(directory).file !== 'undefined') { %> -
-
-

OCR Text Scan (approximately)

-

- This text scan may contain automatically generated text as generated using Apache Tika - and Tesseract. It may not be correct. No effort has been made to correct any of these scans - (so far). These OCR scans are also used in the site's Search feature. Please review the - Search Policy for details about the site features. -

-
<%- h.printReadme(directory) %>
-
-
- <% } %> <% } %>