Skip to content

Commit 5891c75

Browse files
authored
chore: Refactor rule docs format (#15869)
* chore: Refactor rule docs format * Fix HTTP -> HTTPS
1 parent ee69cd3 commit 5891c75

5 files changed

Lines changed: 36 additions & 15 deletions

File tree

docs/.eleventy.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ module.exports = function(eleventyConfig) {
126126
eleventyConfig.addNunjucksAsyncShortcode("link", async function(link) {
127127
const { body: html, url } = await got(link);
128128
const metadata = await metascraper({ html, url });
129-
130-
const encodedURL = encodeURIComponent(link);
131129
const the_url = (new URL(link)); // same as url
132130
const domain = the_url.hostname;
133131

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<nav class="docs-toc c-toc" aria-labelledby="js-toc-label">
2-
{%- if content | toc | safe -%}
2+
{%- if all_content | toc | safe -%}
33
<h2 class="c-toc__label" id="js-toc-label">Table of Contents</h2>
44
<div class="c-toc__panel" id="js-toc-panel">
5-
{{ content | toc | safe }}
5+
{{ all_content | toc | safe }}
66
</div>
77
{%- endif -%}
88
</nav>

docs/src/_includes/layouts/doc.html

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,39 @@
1313
{% include 'components/docs-index.html' %}
1414
</div>
1515

16+
{# Add in related rules and further reading sections to content so TOC is accurate #}
17+
{% set all_content = content %}
18+
{% if related_rules %}
19+
{% set related_rules_content %}
20+
<h2 id="related-rules">Related Rules</h2>
21+
{% related_rules related_rules %}
22+
{% endset %}
23+
24+
{% set all_content = [all_content, related_rules_content] | join %}
25+
{% endif %}
26+
27+
{% if further_reading %}
28+
{% set further_reading_content %}
29+
<h2 id="further-reading">Further Reading</h2>
30+
{# async shortcodes don't work here so need to manually insert later #}
31+
{% endset %}
32+
33+
{% set all_content = [all_content, further_reading_content] | join %}
34+
{% endif %}
35+
1636
<div class="docs-content">
1737
<main id="main" tabindex="-1" class="docs-main">
1838
<h1>{{ title }}</h1>
1939
{% include 'components/docs-toc.html' %}
2040

21-
{{ content | safe }}
41+
{{ all_content | safe }}
42+
43+
{# now insert the async-fetched link data if necessary #}
44+
{% if further_reading %}
45+
{% for url in further_reading %}
46+
{% link url %}
47+
{% endfor %}
48+
{% endif %}
2249

2350
<div class="docs-edit-link">
2451
<a href="{{ edit_link }}" class="c-btn c-btn--secondary">Edit this page</a>

docs/src/rules/block-scoped-var.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ title: block-scoped-var
33
layout: doc
44
edit_link: https://github.com/eslint/eslint/edit/main/docs/src/rules/block-scoped-var.md
55
rule_type: suggestion
6+
further_reading:
7+
- https://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html
8+
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var#var_hoisting
69
---
710

811
Enforces treating `var` as block scoped.
@@ -111,8 +114,3 @@ class C {
111114
}
112115
}
113116
```
114-
115-
## Further Reading
116-
117-
* [JavaScript Scoping and Hoisting](http://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html)
118-
* [var Hoisting](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var#var_hoisting)

docs/src/rules/no-ternary.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ title: no-ternary
33
layout: doc
44
edit_link: https://github.com/eslint/eslint/edit/main/docs/src/rules/no-ternary.md
55
rule_type: suggestion
6+
related_rules:
7+
- no-nested-ternary
8+
- no-unneeded-ternary
69
---
710

811
Disallows ternary operators.
@@ -50,8 +53,3 @@ function quux() {
5053
}
5154
}
5255
```
53-
54-
## Related Rules
55-
56-
* [no-nested-ternary](no-nested-ternary)
57-
* [no-unneeded-ternary](no-unneeded-ternary)

0 commit comments

Comments
 (0)