c68d52a33313810d581029eb2fabf456429a4a54
[websub-hub] / src / template / root-html.js
1 'use strict';
2
3 const th = require('./template-helper');
4
5 function aboutSection() {
6 return ` <section class="about">
7 <h2>What</h2>
8 <p>
9 This is a <a class="external" href="https://www.w3.org/TR/websub/">WebSub</a> Hub service.
10 </p>
11 <p>
12 It facilitates the timely distribution of new content from publishers to subscribers.
13 </p>
14 <aside>
15 The typical use-case is where the content is a blog or news feed, but any type of content may be syndicated.
16 </aside>
17 </section>`;
18 }
19
20 function usageSection(isPublicHub, hubURL) {
21 const usageContent = isPublicHub ? ` <h2>Public Hub</h2>
22 <p>
23 This hub is available as a public resource; any topic which lists it as a hub can be syndicated.
24 </p>
25 <p>
26 To use this hub, your content needs to include some Link relations.
27 </p>
28 <div>
29 <h3>For Any Content</h3>
30 <ul>
31 <li>
32 The content must be served with a <code>Link</code> HTTP header indicating this service as the <code>hub</code> relation.
33 <figure>
34 <figcaption>Example:</figcaption>
35 <code>
36 Link: &lt;${hubURL}&gt;; rel="hub"
37 </code>
38 </figure>
39 </li>
40 <li>
41 The content must be served with a <code>Link</code> HTTP header indicating its own URL with the <code>self</code> relation.
42 <figure>
43 <figcaption>Example:</figcaption>
44 <code>
45 Link: &lt;https://example.com/feed/&gt;; rel="self"
46 </code>
47 </figure>
48 </li>
49 </ul>
50 </div>
51 <div>
52 <h3>For Atom or RSS feeds</h3>
53 <ul>
54 <li>
55 The feed must include a <code>link</code> element within the <code>http://www.w3.org/2005/Atom</code> namespace with the <code>hub</code> relation and this service as the <code>href</code> attribute.
56 <figure>
57 <figcaption>Example:</figcaption>
58 <code>
59 &lt;link xmlns="http://www.w3.org/2005/Atom" href="${hubURL}" rel="hub"&gt;
60 </code>
61 </figure>
62 </li>
63 <li>
64 The feed must include a <code>link</code> element within the <code>http://www.w3.org/2005/Atom</code> namespace with the <code>self</code> relation, its own URL as the <code>href</code> attribute, and its content-type as the <code>type</code> attribute.
65 <figure>
66 <figcaption>Example:</figcaption>
67 <code>
68 &lt;link xmlns="http://www.w3.org/2005/Atom" href="https://example.com/blog/feed" rel="self" type="application/atom+xml"&gt;
69 </code>
70 </figure>
71 </li>
72 <ul>
73 </div>
74 <div>
75 <h3>Publishing Updates</h3>
76 Send a <code>POST</code> request to this hub with Form Data:
77 <ul>
78 <li>
79 <code>hub.mode</code> set to <code>publish</code>
80 </li>
81 <li>
82 <code>hub.url</code> set to the <code>self</code> link relation of the content
83 </li>
84 </ul>
85 </div>`
86 : `
87 <h2>Private Hub</h2>
88 <p>
89 This hub only serves specific topics.
90 </p>`;
91 return `
92 <section class="usage">
93 ${usageContent}
94 </section>`;
95 }
96
97 function contactSection(contactHTML) {
98 let section = '';
99 if (contactHTML) {
100 section = ` <section>
101 ${contactHTML}
102 </section>`;
103 }
104 return section;
105 }
106
107 /**
108 *
109 * @param {Object} ctx
110 * @param {Object} options
111 * @param {Object} options.manager
112 * @param {String} options.adminContactHTML
113 * @param {String} options.manager.pageTitle
114 * @param {String} options.manager.publicHub
115 * @param {Object} options.dingus
116 * @param {String} options.dingus.selfBaseUrl
117 * @returns {String}
118 */
119 module.exports = (ctx, options) => {
120 const pageTitle = options.manager.pageTitle;
121 const isPublicHub = options.manager.publicHub;
122 const contactHTML = options.adminContactHTML;
123 const footerEntries = options.manager.footerEntries;
124 const hubURL = options.dingus.selfBaseUrl || '<s>https://hub.example.com/</s>';
125 const headElements = [];
126 const navLinks = [];
127 const mainContent = [
128 aboutSection(),
129 usageSection(isPublicHub, hubURL),
130 contactSection(contactHTML),
131 ];
132 return th.htmlTemplate(1, pageTitle, headElements, navLinks, mainContent, footerEntries,
133 );
134 };