yurenchen000 / hedgedoc

HedgeDoc - The best platform to write and share markdown.
https://hedgedoc.org
GNU Affero General Public License v3.0
0 stars 0 forks source link

Add image viewer for 1.9.2 #1

Open yurenchen000 opened 2 years ago

yurenchen000 commented 2 years ago

add an image viewer component from https://fengyuanchen.github.io/viewerjs

link: https://github.com/hedgedoc/hedgedoc/issues/2230

TODO:

yurenchen000 commented 2 years ago

How to use

didn't create docker image, just copy files to instance:

https://github.com/yurenchen000/hedgedoc/commits/1.9_add_viewjs

1. copy public/viewjs/*

copy them

public/viewjs/
├── viewer.css
├── viewer.js
└── viewer.png

2. patch js

diff for 1.9.2

diff --git a/lib/csp.js b/lib/csp.js
index 82573bea..46e35b8d 100644
--- a/lib/csp.js
+++ b/lib/csp.js
@@ -27,6 +27,11 @@ const defaultDirectives = {
   mediaSrc: ['*']
 }

+const viewjsDirectives = {
+  scriptSrc: [config.serverURL + '/viewjs/'],
+  styleSrc: [config.serverURL + '/viewjs/']
+}
+
 const disqusDirectives = {
   scriptSrc: ['https://disqus.com', 'https://*.disqus.com', 'https://*.disquscdn.com'],
   styleSrc: ['https://*.disquscdn.com'],
@@ -53,6 +58,7 @@ const allowPDFEmbedDirectives = {
 CspStrategy.computeDirectives = function () {
   const directives = {}
   mergeDirectives(directives, config.csp.directives)
+  mergeDirectives(directives, viewjsDirectives)
   mergeDirectivesIf(config.csp.addDefaults, directives, defaultDirectives)
   mergeDirectivesIf(config.csp.addDisqus, directives, disqusDirectives)
   mergeDirectivesIf(config.csp.addGoogleAnalytics, directives, googleAnalyticsDirectives)
diff --git a/public/views/hedgedoc.ejs b/public/views/hedgedoc.ejs
index 725e11c8..33c66280 100644
--- a/public/views/hedgedoc.ejs
+++ b/public/views/hedgedoc.ejs
@@ -11,4 +11,10 @@
     <%- include('hedgedoc/footer') %>
 </body>

+<!------------- codimd.ejs ----->
+
+<!--- chen added for viewerjs // edit page --->
+<script src="/viewjs/viewer.js"></script>
+<link  href="/viewjs/viewer.css" rel="stylesheet">
+
 </html>
diff --git a/public/views/pretty.ejs b/public/views/pretty.ejs
index 97274ba1..47f56933 100644
--- a/public/views/pretty.ejs
+++ b/public/views/pretty.ejs
@@ -76,3 +76,10 @@
 <script src="<%- serverURL %>/build/MathJax/config/Safe.js" defer></script>
 <%- include('build/pretty-pack-scripts') %>
 <%- include('shared/ga') %>
+
+
+<!------- pretty.ejs ------->
+
+<!--- chen added for viewerjs // view page --->
+<script src="/viewjs/viewer.js"></script>
+<link  href="/viewjs/viewer.css" rel="stylesheet">
yurenchen000 commented 2 years ago

screenshot

codimd_img_viewer.png