annotate js/feed-preview.js @ 49:f4e8aa4d50da version-8

Release version 8
author Guido Berhoerster <guido+feed-preview@berhoerster.name>
date Fri, 05 Jul 2019 13:42:36 +0200
parents 4492db3b277e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
1 /*
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
2 * Copyright (C) 2018 Guido Berhoerster <guido+feed-preview@berhoerster.name>
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
3 *
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
4 * This Source Code Form is subject to the terms of the Mozilla Public
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
7 */
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
8
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
9 'use strict';
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
10
32
4492db3b277e Use human-readable file size units
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 31
diff changeset
11 function formatFileSize(size) {
4492db3b277e Use human-readable file size units
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 31
diff changeset
12 const LIMITS_UNITS = new Map([
4492db3b277e Use human-readable file size units
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 31
diff changeset
13 [1024 * 1024 * 1024, 'GiB'],
4492db3b277e Use human-readable file size units
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 31
diff changeset
14 [1024 * 1024, 'MiB'],
4492db3b277e Use human-readable file size units
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 31
diff changeset
15 [1024, 'KiB'],
4492db3b277e Use human-readable file size units
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 31
diff changeset
16 [0, 'B']
4492db3b277e Use human-readable file size units
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 31
diff changeset
17 ])
4492db3b277e Use human-readable file size units
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 31
diff changeset
18 for (let [limit, unit] of LIMITS_UNITS) {
4492db3b277e Use human-readable file size units
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 31
diff changeset
19 if (size >= limit) {
4492db3b277e Use human-readable file size units
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 31
diff changeset
20 return `${Number(size / limit).toFixed(1)} ${unit}`;
4492db3b277e Use human-readable file size units
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 31
diff changeset
21 }
4492db3b277e Use human-readable file size units
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 31
diff changeset
22 }
4492db3b277e Use human-readable file size units
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 31
diff changeset
23 return '? B';
4492db3b277e Use human-readable file size units
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 31
diff changeset
24 }
4492db3b277e Use human-readable file size units
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 31
diff changeset
25
29
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 26
diff changeset
26 export function renderFeedPreview(feedPreviewDocument, feed,
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 26
diff changeset
27 expandEntriesByDefault) {
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
28 // inject XSL stylesheet which transforms XHTML to HTML allowing the use of
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
29 // the HTML DOM
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
30 let xslFilename = browser.runtime.getURL('web_resources/xhtml-to-html.xsl');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
31 let xmlStylesheetNode =
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
32 feedPreviewDocument.createProcessingInstruction('xml-stylesheet',
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
33 `type="application/xslt+xml" href="${xslFilename}"`);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
34 feedPreviewDocument.firstChild.after(xmlStylesheetNode);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
35
10
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 9
diff changeset
36 feedPreviewDocument.querySelector('#default-stylesheet').href =
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
37 browser.runtime.getURL('web_resources/style/feed-preview.css');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
38
31
76e23b361e92 Allow feed reader addons to subscribe to the currently viewed feed
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
39 // link to the currently viewed feed in order to allow feed reader addons
76e23b361e92 Allow feed reader addons to subscribe to the currently viewed feed
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
40 // to subscribe to it
76e23b361e92 Allow feed reader addons to subscribe to the currently viewed feed
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
41 let feedLinkElement = feedPreviewDocument.querySelector('#feed-link');
76e23b361e92 Allow feed reader addons to subscribe to the currently viewed feed
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
42 feedLinkElement.href = feed.url;
76e23b361e92 Allow feed reader addons to subscribe to the currently viewed feed
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
43 feedLinkElement.type = feed.type;
76e23b361e92 Allow feed reader addons to subscribe to the currently viewed feed
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 29
diff changeset
44
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
45 feedPreviewDocument.querySelector('title').textContent = feed.title;
10
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 9
diff changeset
46
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 9
diff changeset
47 feedPreviewDocument.querySelector('label[for="feed-reader-selection"]')
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 9
diff changeset
48 .textContent = browser.i18n.getMessage('feedReaderSelectionLabel');
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 9
diff changeset
49 feedPreviewDocument.querySelector('[name="subscribe"]').textContent =
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 9
diff changeset
50 browser.i18n.getMessage('subscribeButtonLabel');
ff5e5e3eba32 Implement feed subscription for web-based feed readers
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 9
diff changeset
51
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
52 feedPreviewDocument.querySelector('#feed-title').textContent = feed.title;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
53 feedPreviewDocument.querySelector('#feed-subtitle').textContent =
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
54 feed.subtitle;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
55
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
56 if (typeof feed.logo !== 'undefined') {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
57 let feedLogoTemplate =
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
58 feedPreviewDocument.querySelector('#feed-logo-template');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
59 let logoNode = feedPreviewDocument.importNode(feedLogoTemplate.content,
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
60 true);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
61 let imgElement = logoNode.querySelector('#feed-logo');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
62 imgElement.setAttribute('src', feed.logo.url);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
63 imgElement.setAttribute('alt', feed.logo.title);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
64 feedPreviewDocument.querySelector('#feed-header').prepend(logoNode);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
65 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
66
9
fcd65cf3f634 Simplify the hint shown if there are no entries
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 6
diff changeset
67 feedPreviewDocument.querySelector("#no-entries-hint").textContent =
fcd65cf3f634 Simplify the hint shown if there are no entries
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 6
diff changeset
68 browser.i18n.getMessage('noEntriesHint');
fcd65cf3f634 Simplify the hint shown if there are no entries
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 6
diff changeset
69
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
70 let entryTemplateElement =
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
71 feedPreviewDocument.querySelector('#entry-template');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
72 let entryTitleTemplateElement =
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
73 feedPreviewDocument.querySelector('#entry-title-template');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
74 let entryTitleLinkedTemplateElement =
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
75 feedPreviewDocument.querySelector('#entry-title-linked-template');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
76 let entryFileListTemplateElement =
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
77 feedPreviewDocument.querySelector('#entry-files-list-template');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
78 let entryFileTemplateElement =
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
79 feedPreviewDocument.querySelector('#entry-file-template');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
80 for (let entry of feed.entries) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
81 let entryNode =
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
82 feedPreviewDocument.importNode(entryTemplateElement.content,
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
83 true);
29
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 26
diff changeset
84 entryNode.querySelector('details.entry').open = expandEntriesByDefault;
688d75e554e0 Add option to expand feed entries by default
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 26
diff changeset
85
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
86 let titleElement;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
87 let titleNode;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
88 if (typeof entry.link !== 'undefined') {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
89 titleNode = feedPreviewDocument
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
90 .importNode(entryTitleLinkedTemplateElement.content, true);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
91 titleElement = titleNode.querySelector('.entry-link');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
92 titleElement.href = entry.link;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
93 titleElement.title = entry.title;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
94 } else {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
95 titleNode = feedPreviewDocument
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
96 .importNode(entryTitleTemplateElement.content, true);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
97 titleElement = titleNode.querySelector('.entry-title');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
98 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
99 titleElement.textContent = entry.title;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
100 entryNode.querySelector('.entry-header').prepend(titleNode);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
101
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
102 let timeElement = entryNode.querySelector('.entry-date > time');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
103 timeElement.textContent = entry.date.toLocaleString();
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
104
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
105 let contentElement = entryNode.querySelector('.entry-content');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
106 let contentDocument = new DOMParser().parseFromString(entry.content,
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
107 'text/html');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
108 let stylesheetElement = contentDocument.createElement('link');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
109 stylesheetElement.rel = 'stylesheet';
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
110 stylesheetElement.href =
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
111 browser.runtime.getURL('web_resources/style/entry-content.css');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
112 contentDocument.head.appendChild(stylesheetElement);
26
f0c4a458869c Open links within feed content in a new tab
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
113 // open links in a new tab rather than within the iframe
f0c4a458869c Open links within feed content in a new tab
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
114 for (let linkElement of contentDocument.links) {
f0c4a458869c Open links within feed content in a new tab
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
115 linkElement.target = '_blank';
f0c4a458869c Open links within feed content in a new tab
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 10
diff changeset
116 }
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
117 contentElement.srcdoc = new XMLSerializer()
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
118 .serializeToString(contentDocument);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
119 contentElement.title = entry.title;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
120
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
121 if (entry.files.length > 0) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
122 let fileListNode = feedPreviewDocument
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
123 .importNode(entryFileListTemplateElement.content, true);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
124 fileListNode.querySelector('.entry-files-title').textContent =
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
125 browser.i18n.getMessage('filesTitle');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
126 let fileListElement =
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
127 fileListNode.querySelector('.entry-files-list');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
128
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
129 for (let file of entry.files) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
130 let fileNode = feedPreviewDocument
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
131 .importNode(entryFileTemplateElement.content, true);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
132
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
133 let fileLinkElement =
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
134 fileNode.querySelector('.entry-file-link');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
135 fileLinkElement.href = file.url;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
136 fileLinkElement.title = file.filename;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
137 fileLinkElement.textContent = file.filename;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
138
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
139 fileNode.querySelector('.entry-file-info').textContent =
32
4492db3b277e Use human-readable file size units
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 31
diff changeset
140 `(${file.type}, ${ formatFileSize(file.size)})`;
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
141
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
142 fileListElement.appendChild(fileNode);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
143 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
144
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
145 entryNode.querySelector('.entry').append(fileListNode);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
146 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
147
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
148 feedPreviewDocument.body.append(entryNode);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
149 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
150 }