Skip to content

Commit 081cbf7

Browse files
authored
Merge pull request #10 from tuxu/feature/offline-support
Bundle JS/CSS dependencies for offline use
2 parents dafadc5 + 0265dff commit 081cbf7

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

ipynb-quicklook.xcodeproj/project.pbxproj

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,22 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
215B224E1E3B4FB40055B563 /* template.html in Resources */ = {isa = PBXBuildFile; fileRef = 215B224D1E3B4FB40055B563 /* template.html */; };
1110
219F67471E37F49800CA4392 /* GenerateThumbnailForURL.m in Sources */ = {isa = PBXBuildFile; fileRef = 219F67461E37F49800CA4392 /* GenerateThumbnailForURL.m */; };
1211
219F67491E37F49800CA4392 /* GeneratePreviewForURL.m in Sources */ = {isa = PBXBuildFile; fileRef = 219F67481E37F49800CA4392 /* GeneratePreviewForURL.m */; };
1312
219F674B1E37F49800CA4392 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 219F674A1E37F49800CA4392 /* main.c */; };
1413
219F67541E3AC7E100CA4392 /* HTMLPreviewBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 219F67521E3AC7E100CA4392 /* HTMLPreviewBuilder.h */; };
1514
219F67551E3AC7E100CA4392 /* HTMLPreviewBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 219F67531E3AC7E100CA4392 /* HTMLPreviewBuilder.m */; };
16-
219F67571E3AD15900CA4392 /* nbv.js in Resources */ = {isa = PBXBuildFile; fileRef = 219F67561E3AD15900CA4392 /* nbv.js */; };
1715
/* End PBXBuildFile section */
1816

1917
/* Begin PBXFileReference section */
20-
215B224D1E3B4FB40055B563 /* template.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = template.html; sourceTree = "<group>"; };
2118
219F67431E37F49800CA4392 /* ipynb-quicklook.qlgenerator */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "ipynb-quicklook.qlgenerator"; sourceTree = BUILT_PRODUCTS_DIR; };
2219
219F67461E37F49800CA4392 /* GenerateThumbnailForURL.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GenerateThumbnailForURL.m; sourceTree = "<group>"; };
2320
219F67481E37F49800CA4392 /* GeneratePreviewForURL.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GeneratePreviewForURL.m; sourceTree = "<group>"; };
2421
219F674A1E37F49800CA4392 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = "<group>"; };
2522
219F674C1E37F49800CA4392 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
2623
219F67521E3AC7E100CA4392 /* HTMLPreviewBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLPreviewBuilder.h; sourceTree = "<group>"; };
2724
219F67531E3AC7E100CA4392 /* HTMLPreviewBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HTMLPreviewBuilder.m; sourceTree = "<group>"; wrapsLines = 1; };
28-
219F67561E3AD15900CA4392 /* nbv.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = nbv.js; path = nbviewer.js/lib/nbv.js; sourceTree = SOURCE_ROOT; };
25+
40DA4F1927FF9B5100890202 /* template.html.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = template.html.in; sourceTree = "<group>"; };
2926
/* End PBXFileReference section */
3027

3128
/* Begin PBXFrameworksBuildPhase section */
@@ -58,14 +55,13 @@
5855
219F67451E37F49800CA4392 /* ipynb-quicklook */ = {
5956
isa = PBXGroup;
6057
children = (
61-
215B224D1E3B4FB40055B563 /* template.html */,
58+
40DA4F1927FF9B5100890202 /* template.html.in */,
6259
219F67461E37F49800CA4392 /* GenerateThumbnailForURL.m */,
6360
219F67521E3AC7E100CA4392 /* HTMLPreviewBuilder.h */,
6461
219F67531E3AC7E100CA4392 /* HTMLPreviewBuilder.m */,
6562
219F67481E37F49800CA4392 /* GeneratePreviewForURL.m */,
6663
219F674A1E37F49800CA4392 /* main.c */,
6764
219F674C1E37F49800CA4392 /* Info.plist */,
68-
219F67561E3AD15900CA4392 /* nbv.js */,
6965
);
7066
path = "ipynb-quicklook";
7167
sourceTree = "<group>";
@@ -92,6 +88,7 @@
9288
219F673F1E37F49800CA4392 /* Frameworks */,
9389
219F67401E37F49800CA4392 /* Headers */,
9490
219F67411E37F49800CA4392 /* Resources */,
91+
40DA4F1827FF9AC600890202 /* Run Script */,
9592
);
9693
buildRules = (
9794
);
@@ -122,6 +119,7 @@
122119
developmentRegion = English;
123120
hasScannedForEncodings = 0;
124121
knownRegions = (
122+
English,
125123
en,
126124
);
127125
mainGroup = 219F67391E37F49800CA4392;
@@ -139,13 +137,33 @@
139137
isa = PBXResourcesBuildPhase;
140138
buildActionMask = 2147483647;
141139
files = (
142-
215B224E1E3B4FB40055B563 /* template.html in Resources */,
143-
219F67571E3AD15900CA4392 /* nbv.js in Resources */,
144140
);
145141
runOnlyForDeploymentPostprocessing = 0;
146142
};
147143
/* End PBXResourcesBuildPhase section */
148144

145+
/* Begin PBXShellScriptBuildPhase section */
146+
40DA4F1827FF9AC600890202 /* Run Script */ = {
147+
isa = PBXShellScriptBuildPhase;
148+
buildActionMask = 2147483647;
149+
files = (
150+
);
151+
inputFileListPaths = (
152+
);
153+
inputPaths = (
154+
"$(SRCROOT)/ipynb-quicklook/template.html.in",
155+
);
156+
name = "Run Script";
157+
outputFileListPaths = (
158+
);
159+
outputPaths = (
160+
);
161+
runOnlyForDeploymentPostprocessing = 0;
162+
shellPath = /bin/sh;
163+
shellScript = "# needs: npm install -g inliner\nexport PATH=/opt/homebrew/bin:$PATH\necho \"Inlining JS + CSS dependencies ...\"\nset -ex\noutput_dir=\"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}\"\nmkdir -p $output_dir\noutput=\"$output_dir/template.html\"\ninliner -V\ncp \"$SRCROOT/nbviewer.js/lib/nbv.js\" \"$(dirname \"$SCRIPT_INPUT_FILE_0\")/\"\ncmdline=\"inliner -m \\\"$SCRIPT_INPUT_FILE_0\\\" > \\\"$output\\\"\"\nscript -q -t0 /dev/null sh -c \"$cmdline\"\n";
164+
};
165+
/* End PBXShellScriptBuildPhase section */
166+
149167
/* Begin PBXSourcesBuildPhase section */
150168
219F673E1E37F49800CA4392 /* Sources */ = {
151169
isa = PBXSourcesBuildPhase;
@@ -270,7 +288,7 @@
270288
COMBINE_HIDPI_IMAGES = YES;
271289
INFOPLIST_FILE = "ipynb-quicklook/Info.plist";
272290
INSTALL_PATH = /Library/QuickLook;
273-
MACOSX_DEPLOYMENT_TARGET = 10.7;
291+
MACOSX_DEPLOYMENT_TARGET = 10.9;
274292
PRODUCT_BUNDLE_IDENTIFIER = "com.tinowagner.ipynb-quicklook";
275293
PRODUCT_NAME = "$(TARGET_NAME)";
276294
WRAPPER_EXTENSION = qlgenerator;
@@ -283,7 +301,7 @@
283301
COMBINE_HIDPI_IMAGES = YES;
284302
INFOPLIST_FILE = "ipynb-quicklook/Info.plist";
285303
INSTALL_PATH = /Library/QuickLook;
286-
MACOSX_DEPLOYMENT_TARGET = 10.7;
304+
MACOSX_DEPLOYMENT_TARGET = 10.9;
287305
PRODUCT_BUNDLE_IDENTIFIER = "com.tinowagner.ipynb-quicklook";
288306
PRODUCT_NAME = "$(TARGET_NAME)";
289307
WRAPPER_EXTENSION = qlgenerator;

ipynb-quicklook/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nbv.js

ipynb-quicklook/GeneratePreviewForURL.m

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,10 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
3232
HTMLPreviewBuilder *builder = [[HTMLPreviewBuilder alloc] init];
3333
NSString *html = [builder previewForNotebookData: data];
3434

35-
NSBundle *bundle = [NSBundle bundleForClass:[HTMLPreviewBuilder class]];
36-
NSURL *jsFile = [bundle URLForResource:@"nbv" withExtension:@"js"];
37-
38-
NSData *jsData = [NSData dataWithContentsOfURL:jsFile];
39-
if (!jsData) {
40-
return ioErr;
41-
}
42-
43-
NSDictionary *properties = @{
44-
(__bridge NSString *)kQLPreviewPropertyTextEncodingNameKey : @"UTF-8",
45-
(__bridge NSString *)kQLPreviewPropertyMIMETypeKey : @"text/html",
46-
(__bridge NSString *)kQLPreviewPropertyAttachmentsKey : @{
47-
@"nbv.js" : @{
48-
(__bridge NSString *)kQLPreviewPropertyMIMETypeKey : @"application/javascript",
49-
(__bridge NSString *)kQLPreviewPropertyAttachmentDataKey: jsData,
50-
},
51-
},
52-
};
53-
5435
QLPreviewRequestSetDataRepresentation(preview,
5536
(__bridge CFDataRef)[html dataUsingEncoding:NSUTF8StringEncoding],
5637
kUTTypeHTML,
57-
(__bridge CFDictionaryRef)properties);
38+
NULL);
5839
}
5940
return noErr;
6041
}

ipynb-quicklook/template.html renamed to ipynb-quicklook/template.html.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-zB1R0rpPzHqg7Kpt0Aljp8JPLqbXI3bhnPWROx27a9N0Ll6ZP/+DiW/UqRcLbRjq" crossorigin="anonymous">
1111
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-y23I5Q6l+B6vatafAwxRu/0oK/79VlbSz7Q9aiSZUvyWYIYsd+qj+o24G5ZU2zJz" crossorigin="anonymous"></script>
1212

13-
<script src='cid:nbv.js'></script>
13+
<script src='nbv.js'></script>
1414
<style type='text/css'>
1515
body {
1616
font: 10pt Helvetica Neue, Arial, sans-serif;

0 commit comments

Comments
 (0)