Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
bbd365ab
Commit
bbd365ab
authored
Aug 21, 2020
by
Lyza Danger Gardner
Committed by
Lyza Gardner
Aug 25, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add PDFJS scripts and template
parent
18c74abf
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
557 additions
and
0 deletions
+557
-0
pdfjs-viewer.mustache
dev-server/templates/pdfjs-viewer.mustache
+423
-0
generate-pdfjs-template.py
scripts/generate-pdfjs-template.py
+78
-0
update-pdfjs
scripts/update-pdfjs
+56
-0
No files found.
dev-server/templates/pdfjs-viewer.mustache
0 → 100644
View file @
bbd365ab
This diff is collapsed.
Click to expand it.
scripts/generate-pdfjs-template.py
0 → 100644
View file @
bbd365ab
#!/usr/bin/env python
# This is a helper used by `update-pdfjs` to update the Mustache template for
# serving PDFs with PDFJS with the local dev server.
import
os
import
sys
# Header to insert at the top of the generated PDF.js viewer template
FILE_HEADER
=
"""
<!-- AUTO-GENERATED BY {}. DO NOT EDIT. -->
"""
.
format
(
sys
.
argv
[
0
]
)
# Header to insert after the original `<title>` tag in the PDF viewer HTML
# mustache template.
#
# This header is responsible for:
#
# - Adding a `<base>` tag so that relative URLs in the pre-built viewer HTML
# resolve to the right URL.
# - Injecting custom PDF.js viewer configuration
# - Injecting the Hypothesis client entry point and configuration
#
# The header needs to be inserted after the `<title>` tag so we can override it,
# but before any relative asset links which will be affected by the `<base>`
# tag.
#
HYPOTHESIS_HEADER
=
"""
<!-- Begin Hypothesis modifications -->
<base href="/scripts/pdfjs-2/web/">
<title>via Hypothesis</title>
{#
It's worth noting that this link tag is *not* currently used by the
Hypothesis client to determine the URL of this page. For consistency with
how these pages are served on via, however, we serve it with the PDF.js
viewer application.
-#}
<link rel="canonical" href="{{{ documentUrl }}}"/>
<script>
window.DOCUMENT_URL = '{{{documentUrl}}}';
window.PDF_URL = '{{{ url }}}';
window.CLIENT_URL = '{{{clientUrl}}}'.replace('{current_host}', document.location.hostname);
</script>
<script src="/scripts/pdfjs-init.js"></script>
{# Configure Hypothesis client. #}
<script>
window.hypothesisConfig = function() {
return {
openSidebar: true,
};
};
</script>
<!-- End Hypothesis modifications -->
"""
def
insert_after
(
str_
,
search_str
,
insert_str
):
return
str_
.
replace
(
search_str
,
search_str
+
insert_str
)
input_file_path
=
sys
.
argv
[
1
]
output_file_path
=
sys
.
argv
[
2
]
input_file
=
open
(
input_file_path
,
"r"
)
output_file
=
open
(
output_file_path
,
"w"
)
base_dir
=
os
.
path
.
dirname
(
input_file_path
)
viewer_html
=
input_file
.
read
()
viewer_html
=
insert_after
(
viewer_html
,
"<!DOCTYPE html>"
,
FILE_HEADER
)
viewer_html
=
insert_after
(
viewer_html
,
"</title>"
,
HYPOTHESIS_HEADER
.
replace
(
"$BASEDIR"
,
base_dir
)
)
output_file
.
write
(
viewer_html
)
\ No newline at end of file
scripts/update-pdfjs
0 → 100755
View file @
bbd365ab
#!/bin/sh
set
-eu
# This script fetches the latest build of PDF.js from the viewer demo
# page. It also regenerates the Mustache-templated HTML viewer for use
# by the local devserver.
#
# See https://github.com/mozilla/pdf.js/wiki/Setup-pdf.js-in-a-website#from-examples
#
# To update PDF.js to the latest version:
#
# 1. Create a new branch and run this script.
# 2. Re-start `make dev` and verify that PDFs in the `dev-server/documents/pdf`
# directory work correctly.
# 3. Commit the changes to the `static/` and `templates/` directories inside of
# `dev-server`
#
# If you make changes to the PDF.js viewer template generator only and want to
# regenerate the HTML template, run this script with the `--no-download` flag.
DEST_DIR
=
dev-server/static/scripts/pdfjs-2
PREFIX
=
pdf.js-gh-pages
COMPONENTS
=
"
$PREFIX
/build
$PREFIX
/web
$PREFIX
/LICENSE"
download_pdfjs
=
1
for
arg
in
"
$@
"
do
if
[
"
$arg
"
=
"--no-download"
]
;
then
download_pdfjs
=
""
fi
done
# Download the latest version of the PDF.js library and viewer.
if
[
$download_pdfjs
]
;
then
rm
-rf
$DEST_DIR
mkdir
-p
$DEST_DIR
# Get the latest build of the viewer
curl
-L
https://github.com/mozilla/pdf.js/archive/gh-pages.tar.gz
\
|
tar
-xz
--directory
$DEST_DIR
--strip-components
=
1
$COMPONENTS
# Remove example content from viewer
rm
$DEST_DIR
/web/
*
.pdf
# Remove the check that the PDF being loaded is from the same origin as the
# viewer.
sed
-i
''
-e
's/HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)/true \/* Hypothesis *\//'
$DEST_DIR
/web/viewer.js
fi
# Generate the PDF viewer mustache (HTML) template.
BASEDIR
=
$(
dirname
$0
)
python
\
$BASEDIR
/generate-pdfjs-template.py
\
$DEST_DIR
/web/viewer.html
\
dev-server/templates/pdfjs-viewer.mustache
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment