Skip to content

Commit e2a41dc

Browse files
committed
use more accessible language in Add New Guides/Tutorials
- also switch some code blocks to explicit html so that mdoc code blocks are not escaped.
1 parent 7de6290 commit e2a41dc

File tree

1 file changed

+126
-78
lines changed

1 file changed

+126
-78
lines changed

_overviews/contribute/add-guides.md

Lines changed: 126 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -19,69 +19,83 @@ and is always contribution-ready.
1919

2020
Currently, the _types_ of documentation supported in this repository are:
2121

22-
- **Guides/Overviews**: Definitive guides/overviews of specific language features. Often long, detailed documents,
23-
often produced by members of the Scala team. An example is the excellent [Collections][collections-overview] overview.
22+
- **Guides/Overviews/Books**: Definitive guides/overviews of specific language features. Often long, detailed documents,
23+
often produced by members of the Scala team. An example is the [Collections][collections-overview] overview.
24+
- **References**: The canonical reference for language features, written by members of the Scala team.
25+
These provide the exact specification to understand more subtle aspects of the language. An example is the
26+
[Scala 3 reference][scala-3-reference].
2427
- **Tutorials**: Bite-size, example-rich, and concise articles meant to get a developer up to speed quickly.
2528
- **Cheatsheets**: Quick reference of Scala syntax and behaviors.
2629

2730
### Implementation
2831

2932
The website is statically generated from [Markdown](https://en.wikipedia.org/wiki/Markdown) source using
3033
[Jekyll](https://github.com/mojombo/jekyll), and hosted on [GitHub Pages](https://pages.github.com/).
31-
This workflow was chosen so as to make it as easy as possible for core committers and the community alike
32-
to produce HTML documentation, and as easy as possible to publish it in a central location.
34+
This workflow was chosen to help contributors to focus on writing helpful content, rather than on configuration and
35+
boilerplate. It also aids publishing a static site in a central location.
3336

3437
The markdown syntax being used supports [Maruku](https://github.com/bhollis/maruku) extensions, and has automatic
3538
syntax highlighting, without the need for any tags.
3639

3740
Additionally [mdoc](https://github.com/scalameta/mdoc) is used during pull requests to validate Scala code blocks.
38-
To use this feature you must use the backtick notation as documented by mdoc. Note that only validation is done.
39-
The output files from mdoc are not used in the building of the tutorial. Use `mdoc` or `mdoc:fail` for your code blocks.
41+
To use this feature you must use the backtick notation as documented by mdoc,
42+
[see here](#code-blocks) for an example.
43+
44+
**Note:** only validation of code is done by mdoc, and no extra output is generated.
4045

4146
## Submitting Docs
4247

43-
For one to contribute a document, one must simply
48+
For you to contribute a document, first
4449
[fork](https://help.github.com/articles/fork-a-repo/) the
45-
[repo](https://github.com/scala/docs.scala-lang), write their article in
46-
[Markdown](https://daringfireball.net/projects/markdown/syntax) (example below), and submit a pull request. That's it.
50+
[repo](https://github.com/scala/docs.scala-lang), then write your article in
51+
[Markdown](https://daringfireball.net/projects/markdown/syntax) (example below), and finally submit a pull request.
4752
Likely after some edits and discussion, your document will be made live
4853
on [docs.scala-lang.org][home].
4954

5055
---
51-
layout: overview
56+
layout: singlepage-overview
5257
title: My Awesome Title
5358
---
5459

5560
## An h2 Header in Markdown
5661

5762
And a paragraph, with a [link](https://www.scala-lang.org).
5863

59-
One can contribute code in a markdown document by either
60-
- indenting it by 4 spaces
61-
- surrounding by triple backticks, as shown below
62-
- in-line by putting backticks around it, e.g. `def foo`.
64+
You can contribute code in a markdown document by either
65+
- in-line by putting backticks around it,
66+
- surrounding by triple backticks,
67+
- or indenting it by 4 spaces, e.g.:
68+
69+
~~~
70+
inline example: `val x = 23`
71+
72+
block example:
73+
```scala
74+
println("hello")
75+
```
76+
77+
indented example:
6378
64-
```scala
65-
println("hello")
66-
```
79+
case class Foo(x: Int)
80+
~~~
6781

68-
Everything else is automatically generated for you; tables of contents, and most index pages. And of course, the
69-
styling is already taken care of for you.
82+
Tables of contents will be automatically generated in a sidebar for your document, and syntax highlighting
83+
is provided.
7084

7185
### Criteria for Docs to be Accepted
7286

73-
The goal of this documentation repository is to be tighter and more organized than other community-driven documentation platforms, like wikis. As such, any document pulled in for inclusion on
74-
[docs.scala-lang.org][home] must:
87+
The goal of this documentation repository is to be highly curated, rather than the approach by other community-driven
88+
documentation platforms, like wikis. Therefore, to be included on [docs.scala-lang.org][home], a document must:
7589

7690
- **"fit in"** to the repository ( _i.e.,_ it should not be a complete duplicate of another article),
77-
- **be polished** it must be thorough, complete, correct, organized, and "article-like" (personal programming notes
78-
don't quite fit.)
79-
- **be maintained** if the document might require revisions from time to time, be prepared to keep it up to date, or
91+
- **be polished**, i.e. it must be thorough, complete, correct, and organized; written as an article to be understood
92+
by many users.
93+
- **be maintained**, if the document might require revisions from time to time, be prepared to keep it up to date, or
8094
nominate someone to take ownership.
8195

8296
If you have something you're thinking about contributing, or that you're thinking about writing in order to contribute
8397
-- we'd love to consider it! Please don't hesitate to use GitHub issues and pull requests and the
84-
\#scala-contributors room [on Discord](https://discord.com/invite/scala) for any questions, concerns,
98+
`#scala-contributors` room [on Discord](https://discord.com/invite/scala) for any questions, concerns,
8599
clarifications, etc.
86100

87101
## Document Templates
@@ -90,38 +104,36 @@ clarifications, etc.
90104
91105
### Guides/Overviews
92106

93-
A guide or an overview that can be logically placed on **one** page must be placed in the directory
94-
`_overviews/RELEVANT-CATEGORY/_posts` with the file name in the format `YYYY-MM-dd-title-separated-by-dashes.md`,
95-
and header:
107+
A guide or an overview that can be logically placed on **one** markdown page should be placed in the directory
108+
`_overviews/RELEVANT-CATEGORY/`. It should have the header:
96109

97110
---
98-
layout: overview
111+
layout: singlepage-overview
99112
title: YOUR TITLE
100113
---
101114

102-
The rest of the document should, of course, be written in [Markdown](https://en.wikipedia.org/wiki/Markdown).
115+
The rest of the document will be written in [Markdown](https://en.wikipedia.org/wiki/Markdown) syntax.
103116

104-
At the moment, `RELEVANT-CATEGORY` corresponds to only a single category, "core," because we are currently focusing on
105-
building up documentation of core libraries. However, expect more categories here in the future.
117+
You may substitute `RELEVANT-CATEGORY` for any directory that is related, or create a new one if one is not suitable.
106118

107-
If your document consists of **multiple** pages, like the [Collections][collections-overview] overview, an ordering
108-
must be specified, by numbering documents in their logical order with `num`, and a name must be assigned to the
109-
collection of pages using `partof`. For example, the following header might be used for a document in the collections
110-
overview:
119+
If your guide/overview consists of **multiple** pages, like the [Collections][collections-overview] overview,
120+
an ordering must be specified, by numbering documents in their logical order with the `num` tag in the header,
121+
and a name must be assigned to the collection of pages using the `partof` tag.
122+
For example, the following header might be used for a document in the collections overview:
111123

112124
---
113-
layout: overview
125+
layout: multipage-overview
114126
title: YOUR TITLE
115127

116128
partof: collections
117129
num: 10
118130
---
119131

120-
A **single** document in the collection must contain a tag in the header, `outof`, that indicates the total number of
121-
documents in the large overview. Putting it on the last page in the overview is often best:
132+
**At least one** document in the collection must contain a tag in the header, `outof`, that indicates the total number
133+
of documents in the large overview. Putting it on the last page in the overview is often best:
122134

123135
---
124-
layout: overview
136+
layout: multipage-overview
125137
title: YOUR TITLE
126138

127139
partof: collections
@@ -130,61 +142,90 @@ documents in the large overview. Putting it on the last page in the overview is
130142
---
131143

132144
Index pages, such as [docs.scala-lang.org/overviews/index.html][overviews-index] are
133-
generated, by reading data from a configuration file, such as `_data/overviews.yml`, so your overview should be
145+
generated by reading data from a configuration file, such as `_data/overviews.yml`, so your overview should be
134146
placed into a category there.
135147

136148
### Tutorials
137149

138-
At the moment, tutorials are written the same as Guides/Overviews, except that their link must be added to
139-
the metadata of `/tutorials.md`. e.g. for the [Scala With Maven][scala-with-maven] tutorial, the
140-
metadata of `/tutorials.md` looks like
150+
Tutorials are different to guides, they should be written in a much more concise, task-oriented style,
151+
usually on a single page.
152+
153+
Similar to guides, tutorials also use the same markdown header.
154+
155+
Once the tutorial is written, to aid user navigation their link must be added to
156+
the metadata of `/tutorials.md`. e.g. it could look like
141157

142158
---
143159
layout: inner-page-parent
144160
title: Tutorials
145161

146162
tutorials:
147163
...
148-
- title: "Scala with Maven"
149-
url: "/tutorials/scala-with-maven.html"
150-
description: "Create a Scala project with Maven."
151-
icon: code
164+
- title: My New Tutorial
165+
url: "/tutorials/my-new-tutorial.html"
166+
description: "Learn How To Do This Specific Task"
167+
icon: code
152168
---
153169

154-
For a single-page tutorial, the typical directory to place them in is `_overviews/tutorials`.
170+
You must also add the tutorial to the drop down list in the navigation bar. To do this, add an extra entry to
171+
`_data/doc-nav-header.yml`. i.e.
172+
173+
---
174+
- title: Getting Started
175+
url: "/getting-started/index.html"
176+
- title: Learn
177+
...
178+
- title: Tutorials
179+
url: "#"
180+
submenu:
181+
...
182+
- title: My New Tutorial
183+
url: "/tutorials/my-new-tutorial.html"
184+
...
185+
---
155186

156187
### Cheatsheets
157188

158-
For now, cheatsheets are assumed to be in the form of tables. To contribute a cheatsheet, one must simply produce their
159-
cheatsheet as a Markdown table, with the following header:
189+
Cheatsheets have a special layout, and the content is expected to be a markdown table. To contribute a cheatsheet,
190+
you should use the following format:
160191

161192
---
162193
layout: cheatsheet
163194
title: YOUR TITLE
164195
by: YOUR NAME
165196
about: SOME TEXT ABOUT THE CHEAT SHEET.
166197
---
198+
| Title A | Title B |
199+
|---------|---------|
200+
| content | more |
167201

168202
### Code blocks
169203

170204
The site build process uses [mdoc](https://scalameta.org/mdoc/) to typecheck
171205
code snippets in markdown. This is a great way to ensure the code snippets that
172-
you're including typecheck and are valid. Here are a few quick types to get
173-
started.
206+
you're including typecheck and are valid. Here are a few quick tips to get
207+
started:
174208

175-
To get started, add `mdoc` after `scala` when you are creating a
209+
First, add `mdoc` after `scala` when you are creating a
176210
code block. The `mdoc` modifier here will make sure that `mdoc` runs the code
177211
snippet and ensures that it's valid.
178212

179-
```scala mdoc
180-
val a = 1
181-
```
213+
<div class="language-plaintext highlighter-rouge">
214+
<div class="highlight">
215+
<pre class="highlight">
216+
<code class="hljs scala">&#96;&#96;&#96;scala mdoc
217+
<span class="hljs-keyword">val</span> a = <span class="hljs-number">1</span>
218+
&#96;&#96;&#96;
219+
</code></pre></div></div>
220+
182221
If you have a snippet that you expect to fail, you can also account for this by
183222
using `mdoc:fail` for a compile error `mdoc:crash` for a runtime-error.
184223

185-
```scala mdoc:fail
186-
val b: String = 3 // won't compile
187-
```
224+
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code class="hljs scala">&#96;&#96;&#96;scala mdoc:fail
225+
<span class="hljs-keyword">val</span> b: <span class="hljs-type">String</span> = <span class="hljs-number">3</span> <span class="hljs-comment">// won't compile</span>
226+
```
227+
</code></pre></div></div>
228+
188229
Keep in mind that a single file is all compiled as a single unit, so you can't
189230
redefine a variable that was defined above in another code snippet. _However_
190231
there are a couple ways to get around this. Firstly, you can use the `mdoc:nest`
@@ -193,29 +234,36 @@ essentially "hide" the snippet from the others. Another way around this is to
193234
use the `mdoc:reset` modifier, which _resets_ and forgets about everything up
194235
above. Here is an example using the various modifiers.
195236
196-
```scala mdoc
197-
import java.time.Instant
237+
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code class="hljs scala">&#96;&#96;&#96;scala mdoc
238+
<span class="hljs-keyword">import</span> java.time.<span class="hljs-type">Instant</span>
239+
240+
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">now</span></span>() = <span class="hljs-type">Instant</span>.now()
241+
<span class="hljs-class"><span class="hljs-keyword">object</span> <span class="hljs-title">Foo</span> </span>{}
242+
```
243+
</code></pre></div></div>
244+
245+
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code class="hljs scala">&#96;&#96;&#96;scala mdoc:nest
246+
<span class="hljs-keyword">case</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Foo</span>(<span class="hljs-params">a: <span class="hljs-type">Int</span></span>) <span class="hljs-comment">// conflicts with Foo above, but it's nested so it's fine</span></span>
247+
```
248+
</code></pre></div></div>
198249
199-
def now() = Instant.now()
200-
object Foo {}
201-
```
250+
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code class="hljs scala">&#96;&#96;&#96;scala mdoc
251+
<span class="hljs-keyword">val</span> a = <span class="hljs-string">s"The time is <span class="hljs-subst">${now()}</span>"</span> <span class="hljs-comment">// still have access to the now method from above</span>
252+
```
253+
</code></pre></div></div>
202254

203-
```scala mdoc:nest
204-
case class Foo(a: Int) // conflicts with Foo above, but it's nested so it's fine
205-
```
255+
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code class="hljs scala">&#96;&#96;&#96;scala mdoc:reset
256+
<span class="hljs-keyword">case</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Foo</span>(<span class="hljs-params">a: <span class="hljs-type">String</span></span>) <span class="hljs-comment">// forget the previous Foo's and start fresh</span></span>
257+
```
258+
</code></pre></div></div>
206259
207-
```scala mdoc
208-
val a = s"The time is ${now()}" // still have access to the now method from above
209-
```
210-
```scala mdoc:reset
211-
case class Foo(a: String) // forget the previous Foo's and start fresh
212-
```
213-
```scala mdoc
214-
val myFoo = Foo("hi") // now we only have access to the last Foo
215-
```
260+
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code class="hljs scala">&#96;&#96;&#96;scala mdoc
261+
<span class="hljs-keyword">val</span> myFoo = <span class="hljs-type">Foo</span>(<span class="hljs-string">"hi"</span>) <span class="hljs-comment">// now we only have access to the last Foo</span>
262+
```
263+
</code></pre></div></div>
216264

217265
[collections-overview]: {% link _overviews/collections-2.13/introduction.md %}
218-
[scala-with-maven]: {% link _overviews/tutorials/scala-with-maven.md %}
219266
[why-contribute]: {% link contribute.md %}
220267
[home]: {% link index.md %}
221268
[overviews-index]: {% link _overviews/index.md %}
269+
[scala-3-reference]: https://docs.scala-lang.org/scala3/reference/overview.html

0 commit comments

Comments
 (0)