8797564e54e93b1ef816de4c4e4b6e01269e3b7c
[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 <li>
50 Ideally, these should be combined in one header.
51 <figure>
52 <figcaption>Example:</figcaption>
53 <code>
54 Link: &lt;${hubURL}&gt;; rel="hub", &lt;https://example.com/feed/&gt;; rel="self"
55 </code>
56 </figure>
57 </li>
58 </ul>
59 </div>
60 <div>
61 <h3>For Atom or RSS feeds</h3>
62 <ul>
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>hub</code> relation and this service as the <code>href</code> attribute.
65 <figure>
66 <figcaption>Example:</figcaption>
67 <code>
68 &lt;link xmlns="http://www.w3.org/2005/Atom" href="${hubURL}" rel="hub"&gt;
69 </code>
70 </figure>
71 </li>
72 <li>
73 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.
74 <figure>
75 <figcaption>Example:</figcaption>
76 <code>
77 &lt;link xmlns="http://www.w3.org/2005/Atom" href="https://example.com/blog/feed" rel="self" type="application/atom+xml"&gt;
78 </code>
79 </figure>
80 </li>
81 <ul>
82 </div>
83 <div>
84 <h3>Publishing Updates</h3>
85 To notify the Hub that a topic&apos;s content has been updated and should be distributed to subscribers, send a <code>POST</code> request with Form Data (<code>application/x-www-form-urlencoded</code>):
86 <ul>
87 <li>
88 <code>hub.mode</code> set to <code>publish</code>
89 </li>
90 <li>
91 <code>hub.url</code> set to the <code>self</code> link relation of the content (this value may be set multiple times, to update more than one topic)
92 </li>
93 </ul>
94 <figure>
95 <figcaption>Example:</figcaption>
96 <code>
97 curl ${hubURL} -d'hub.mode=publish' -d'hub.url=https://example.com/blog_one/feed' -d'hub.url=https://example.com/blog_two/feed'
98 </code>
99 </figure>
100 </div>`
101 : `
102 <h2>Private Hub</h2>
103 <p>
104 This hub only serves specific topics.
105 </p>`;
106 return `
107 <section class="usage">
108 ${usageContent}
109 </section>`;
110 }
111
112 function contactSection(contactHTML) {
113 let section = '';
114 if (contactHTML) {
115 section = ` <section>
116 ${contactHTML}
117 </section>`;
118 }
119 return section;
120 }
121
122 /**
123 *
124 * @param {Object} ctx
125 * @param {Object} options
126 * @param {Object} options.manager
127 * @param {String} options.adminContactHTML
128 * @param {String} options.manager.pageTitle
129 * @param {String} options.manager.publicHub
130 * @param {Object} options.dingus
131 * @param {String} options.dingus.selfBaseUrl
132 * @returns {String}
133 */
134 module.exports = (ctx, options) => {
135 const pageTitle = options.manager.pageTitle;
136 const isPublicHub = options.manager.publicHub;
137 const contactHTML = options.adminContactHTML;
138 const footerEntries = options.manager.footerEntries;
139 const hubURL = options.dingus.selfBaseUrl || '<s>https://hub.example.com/</s>';
140 const headElements = [];
141 const navLinks = [];
142 const mainContent = [
143 aboutSection(),
144 usageSection(isPublicHub, hubURL),
145 contactSection(contactHTML),
146 ];
147 return th.htmlTemplate(1, pageTitle, headElements, navLinks, mainContent, footerEntries,
148 );
149 };