UNPKG

13.8 kBHTMLView Raw
1<!doctype html>
2<meta charset="utf-8">
3<script src="../dist/template.js"></script>
4<style>
5.fake-img {
6 background: #bbb;
7 border: 1px solid rgba(0, 0, 0, 0.1);
8 box-shadow: 0 0px 4px rgba(0, 0, 0, 0.1);
9 margin-bottom: 12px;
10}
11.fake-img p {
12 font-family: monospace;
13 color: white;
14 text-align: left;
15 margin: 12px 0;
16 text-align: center;
17 font-size: 16px;
18}
19</style>
20
21<dt-article>
22 <h1>How to Create a Distill Article</h1>
23 <h2>A collection of examples and best practices for creating interactive explanatory articles using the Distill web framework</h2>
24 <hr>
25 <h2>Getting Started</h2>
26 <p>Distill ships with a CSS framework and a collection of custom web components that make building interactive academic articles easier than with raw HTML, CSS and JavaScript. At its simplest, each distill post is just a single HTML file with one special script tag.</p>
27 <dt-code block language="html">
28 &lt;!doctype html&gt;
29 &lt;meta charset="utf-8"&gt;
30 &lt;script src="http://distill.pub/template.js"&gt;&lt;/script&gt;
31
32 &lt;dt-article&gt;
33 &lt;h1&gt;Hello World&lt;/h1&gt;
34 &lt;/dt-article&gt;
35 </dt-code>
36 <p>This script tag will modify your post in your browser, adding the distill styling and functionality. When we publish your article, we will bake in these transformations, but during development it’s handy to be able to preview it locally (It even works without a web server).</p>
37 <p>A typical distill post will be quite a bit longer than the one above. Below is a more complete example. Don’t worry if some of the tags don’t make sense, they’re all documented further in this post.</p>
38 <dt-code block language="html">
39 &lt;!doctype html&gt;
40 &lt;meta charset="utf-8"&gt;
41 &lt;script src="http://distill.pub/template.js"&gt;&lt;/script&gt;
42
43 &lt;script type="text/front-matter"&gt;
44 title: Article Title
45 description: Description of the post
46 published: Jan 10, 2017
47 authors:
48 - Chris Olah: http://colah.github.io
49 - Shan Carter: http://shancarter.com
50 affiliations:
51 - Google Brain: http://g.co/brain
52 - Google Brain: http://g.co/brain
53 &lt;/script&gt;
54
55 &lt;dt-article&gt;
56 &lt;h1&gt;Hello World&lt;/h1&gt;
57 &lt;h2&gt;A description of the article&lt;/h2&gt;
58 &lt;dt-byline&gt;&lt;/dt-byline&gt;
59 &lt;p&gt;This is the first paragraph of the article.&lt;/p&gt;
60 &lt;p&gt;We can also cite &lt;dt-cite key="gregor2015draw"&gt;&lt;/dt-cite&gt; external publications.&lt;/p&gt;
61 &lt;/dt-article&gt;
62
63 &lt;dt-appendix&gt;
64 &lt;/dt-appendix&gt;
65
66 &lt;script type="text/bibliography"&gt;
67 @article{gregor2015draw,
68 title={DRAW: A recurrent neural network for image generation},
69 author={Gregor, Karol and Danihelka, Ivo and Graves, Alex and Rezende, Danilo Jimenez and Wierstra, Daan},
70 journal={arXivreprint arXiv:1502.04623},
71 year={2015},
72 url={https://arxiv.org/pdf/1502.04623.pdf}
73 }
74 &lt;/script&gt;
75 </dt-code>
76 <!-- <hr>
77 <h2>Markdown</h2>
78 <p>Markdown is supported as an alternative to html for the <dt-code language="html">&lt;dt-article&gt;</dt-code> element. </p>
79 <dt-code block language="html">
80 &lt;!doctype html&gt;
81 &lt;meta charset="utf-8"&gt;
82 &lt;script src="../dist/template.min.js"&gt;&lt;/script&gt;
83 &lt;dt-article markdown&gt;
84 # Hello World
85
86 ## A description of the post
87
88 First paragraph of the article.
89 &lt;/dt-article&gt;
90 &lt;script type="text/bibliography"&gt;&lt;/script&gt;
91 </dt-code>
92 <p>We use <a href="https://github.com/chjj/marked">marked</a> as the rendering engine, with <a href="https://help.github.com/articles/basic-writing-and-formatting-syntax/">github flavored markdown</a> and <a href="https://daringfireball.net/projects/smartypants/">smartypants</a> enabled. In development mode the markdown is translated in the client after the dom content has loaded, but when published, the translation is precompiled.</p> -->
93
94 <hr>
95 <h2>Project Structure</h2>
96 <p>Because all the templating is delivered via a script tag, you are generally free to develop however you are most comfortable. The only requirements are that each article must be its own Github repository. The simplest setup would be a repository that contained a single HTML file, along with any additional assets, like images or javascript files. Note, in this default setup, all files in the root of the repository will be published. Note, also, in this configuration you generally will not even need to run a static local webserver. You can just open the <dt-code>index.html</dt-code> file in your browser to preview.</p>
97
98 <dt-code block language="html">
99 image.jpg
100 index.html
101 script.js
102 </dt-code>
103
104 <p>If you have a more complicated build process, or have files you don’t want published, put your output in a <dt-code>public</dt-code> folder and we will only publish its contents.</p>
105
106 <dt-code block language="html">
107 build/
108 _index.html
109 package.json
110 public/
111 index.html
112 image.jpg
113 </dt-code>
114
115 <hr>
116 <h2>Front Matter</h2>
117 <p>You’ll need to describe some data about you post — title, description, authors, etc. For this use the <dt-code language="html">&lt;script type="text/front-matter"&gt;</dt-code> tag.</p>
118 <dt-code block language="html">
119 &lt;script type="text/front-matter"&gt;
120 title: Article Title
121 description: Description of the post
122 authors:
123 - Chris Olah: http://colah.github.io
124 - Shan Carter: http://shancarter.com
125 affiliations:
126 - Google Brain: http://g.co/brain
127 - Google Brain: http://g.co/brain
128 &lt;/script&gt;
129 </dt-code>
130 <!-- <p>You can also use an external JSON file if you like. We will automatically make a request for a <dt-code>distill.json</dt-code> file if there is no <dt-code language="html">&lt;script type="text/front-matter"&gt;</dt-code> element on the page, or you can point to another file with the <dt-code>src</dt-code> attribute. In production, these files will be inlined into the document.</p>
131 <dt-code block language="html">
132 &lt;script type="text/front-matter" src="./distill.json"&gt;&lt;/script&gt;
133 </dt-code> -->
134 <hr>
135 <h2>Citations</h2>
136 <p>Bibtex is the supported way of making academic citations. You first need have a global definition of all your possible citations. For this we’ll use the <dt-code language="html">&lt;script type="text/bibliography"&gt;</dt-code> element.</p>
137 <dt-code block language="html">
138 &lt;script type="text/bibliography"&gt;
139 @article{gregor2015draw,
140 title={DRAW: A recurrent neural network for image generation},
141 author={Gregor, Karol and Danihelka, Ivo and Graves, Alex and Rezende, Danilo Jimenez and Wierstra, Daan},
142 journal={arXivreprint arXiv:1502.04623},
143 year={2015},
144 url={https://arxiv.org/pdf/1502.04623.pdf},
145 }
146 &lt;/script&gt;
147 </dt-code>
148 <p>(We strongly encourage you to populate the <dt-code>url</dt-code> bibtex field where possible so that we can provide links for citations.)</p>
149 <!-- <p>Like with the <dt-code language="html">&lt;script type="text/front-matter"&gt;</dt-code> element, you can alternatively reference an external file with the <dt-code>src</dt-code> attribute. If no <dt-code language="html">&lt;script type="text/bibliography"&gt;</dt-code> element is found on the page, a request will automatically be made for <dt-code>bibliography.bib</dt-code>. In production, these files will be inlined into the document.</p>
150 <dt-code block language="html">
151 &lt;script type="text/bibliography" src="bibliography.bib"&gt;&lt;/script&gt;
152 </dt-code> -->
153 <p>Citations are then used in the article body with the <dt-code language="html">&lt;dt-cite&gt;</dt-code> tag. The <dt-code>key</dt-code> attribute is a reference to the id provided in the bibiography. The <dt-code>key</dt-code> attribute can take multiple ids, separated by commas.</p>
154 <dt-code block language="html">
155 &lt;dt-cite key="gregor2015draw"&gt;&lt;/dt-cite&gt;
156 </dt-code>
157 <script type="text/bibliography">
158 @article{gregor2015draw,
159 title={DRAW: A recurrent neural network for image generation},
160 author={Gregor, Karol and Danihelka, Ivo and Graves, Alex and Rezende, Danilo Jimenez and Wierstra, Daan},
161 journal={arXivreprint arXiv:1502.04623},
162 year={2015},
163 url={https://arxiv.org/pdf/1502.04623.pdf},
164 }
165 </script>
166 <p>The citation is presented inline like this: <dt-cite key="gregor2015draw"></dt-cite> (a number that displays more information on hover). If you have an appendix, a bibliography is automatically created and populated in it.</p>
167 <p>Distill chose a numerical inline citation style to improve readability of citation dense articles and because many of the benefits of longer citations are obviated by dispalying more information on hover. However, we consider it good style to mention author last names if you discuss something at length and it fits into the flow well -- the authors are human and it's nice for them to have the community associate them with their work.</p>
168
169
170 <hr>
171 <h2>Footnotes</h2>
172 <p>Just wrap the text you would like to show up in a footnote in a <dt-code language="html">&lt;dt-fn&gt;</dt-code> tag. The number of the footnote will be automatically generated. <dt-fn>This text will be shown on hover.</dt-fn></p>
173 <dt-code block language="html">
174 &lt;dt-fn&gt;This will become a hoverable footnote.&lt;/dt-fn&gt;
175 </dt-code>
176 <dt-footnote-body ref="blah"></dt-footnote-body>
177
178 <hr>
179 <h2>Code Blocks</h2>
180 <p>Syntax highlighting is provided within <dt-code language="html">&lt;dt-code&gt;</dt-code> tags. An example of inline code snippets: <dt-code language="html">&lt;dt-code language="html"&gt;let x = 10;&lt;/dt-code&gt;</dt-code>. For larger blocks of code, add a <dt-code>block</dt-code> attribute:</p>
181 <dt-code block language="html">
182 &lt;dt-code block language="javascript"&gt;
183 var x = 25;
184 function(x){
185 return x * x;
186 }
187 &lt;/dt-code&gt;
188 </dt-code>
189
190 <!--
191 <hr>
192 <h2>Math</h2>
193 -->
194 <hr>
195 <h2>Layouts</h2>
196 <p>The main text column is referred to as the body. It is the assumed layout of any direct descendents of the <code>dt-article</code> element.</p>
197 <div class="fake-img l-body"><p>.l-body</p></div>
198 <p>For images you want to display a little larger, try these:</p>
199 <div class="fake-img l-middle"><p>.l-middle</p></div>
200 <div class="fake-img l-page"><p>.l-page</p></div>
201 <p>All of these have an <dt-code>outset</dt-code> variant if you want to poke out from the body text a little bit. For instance:</p>
202 <div class="fake-img l-body-outset"><p>.l-body-outset</p></div>
203 <div class="fake-img l-middle-outset"><p>.l-middle-outset</p></div>
204 <div class="fake-img l-page-outset"><p>.l-page-outset</p></div>
205 <p>Occasionally you’ll want to use the full browser width. For this, use <dt-code>.l-screen</dt-code>. You can also inset the element a little from the edge of the browser by using the inset variant.</p>
206 <div class="fake-img l-screen"><p>.l-screen</p></div>
207 <div class="fake-img l-screen-inset"><p>.l-screen-inset</p></div>
208 <p>Often you want to position smaller images so as not to completely interrupt the flow of your text. Or perhaps you want to put some text in the margin as an aside or to signal that it’s optional content. For these cases we’ll use the float-based layouts.</p>
209 <div class="fake-img l-body side"><p>.l-body.side</p></div>
210 <div class="fake-img l-middle side"><p>.l-middle.side</p></div>
211 <div class="fake-img l-page side"><p>.l-page.side</p></div>
212 <p>They are all floated to the right and anchored to the right-hand edge of the position you specify. By default, each will take up approximately half of the width of the standard layout position, but you can override the width with a more specific selector. </p>
213 <div class="fake-img l-gutter"><p>.l-gutter</p></div>
214 <p>The final layout is for marginalia, asides, and footnotes. It does not interrupt the normal flow of <code>.l-body</code> sized text except on mobile screen sizes.</p>
215 <p>You can also use an alternate centered layout by adding a <dt-code>centered</dt-code> class to the <dt-code>dt-article</dt-code> element.</p>
216 <dt-code block language="html">
217 &lt;dt-article class="centered"&gt;
218 &lt;h1&gt;Hello World&lt;/h1&gt;
219 &lt;/dt-article&gt;
220 </dt-code>
221 <p>You can toggle it on this article by <a onclick="document.querySelector('dt-article').classList.toggle('centered');">clicking here</a></p>
222 <section class="centered">
223
224 </section>
225
226 <hr>
227 <h2>Appendix</h2>
228
229 <p>An appendix can be added after your article, using the <dt-code language="html">&lt;dt-appendix&gt;</dt-code> tag.</p>
230
231 <dt-code block language="html">
232 &lt;dt-article&gt;
233 ...
234 &lt;/dt-article&gt;
235
236 &lt;dt-appendix&gt;
237 &lt;h3&gt;Appendix Section Title&lt;/h3&gt;
238 &lt;p&gt;section content&lt;p&gt;
239 &lt;/dt-appendix&gt;
240 </dt-code>
241
242 <p>You may wish to include the following sections in your appendix:</p>
243 <ul>
244 <li><b>Acknowledgments</b>: This is a place to recognize people and institutions. It may also be a good place to acknowledge and cite software that makes your work possible (eg. TensorFlow, OpenAI Gym).</li>
245 <li><b>Author Contributions</b>: We strongly encourage you to include an author contributions statement briefly describing what each author did.</li>
246 </ul>
247
248 <hr>
249 <h2>And You’re Off</h2>
250 <p>That should do it. If you have any questions or bugs to file, feel free to <a href="https://github.com/distillpub/template/issues/new">open an issue on GitHub</a>.</p>
251<!--
252 <hr>
253 <h2>Including External Files</h2> -->
254
255</dt-article>