Skip to content

Commit f4bd856

Browse files
authored
Sander/postrender sample (#161)
* refactor(scully dist files): move scully dist files into dist Due to a flake in typescript, we needed to move the dist files of scully outside of the scully's source folder * chore(move to dist cleanup): some small cleanups after moving scully bin into dist * refactor(outfolder rename to outdir): change to name outDir to be consistem with tsconfig * feat(postrender): postrender makes it possible to run additional render plugins on a given route * feat(tocplugin.js): a sample TOC plugin a additional plugin to show the use of postRenderers * fix(config.ts): fix typo fix an typo
1 parent bced623 commit f4bd856

File tree

8 files changed

+277
-294
lines changed

8 files changed

+277
-294
lines changed

CONTRIBUTING.md

Lines changed: 74 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
We would love for you to contribute to Scully and help make it even better than it is
44
today! As a contributor, here are the guidelines we would like you to follow:
55

6-
- [Code of Conduct](#coc)
7-
- [Question or Problem?](#question)
8-
- [Issues and Bugs](#issue)
9-
- [Feature Requests](#feature)
10-
- [Submission Guidelines](#submit)
11-
- [Coding Rules](#rules)
12-
- [Commit Message Guidelines](#commit)
13-
- [Signing the CLA](#signing-the-cla)
6+
- [Code of Conduct](#coc)
7+
- [Question or Problem?](#question)
8+
- [Issues and Bugs](#issue)
9+
- [Feature Requests](#feature)
10+
- [Submission Guidelines](#submit)
11+
- [Coding Rules](#rules)
12+
- [Commit Message Guidelines](#commit)
13+
- [Signing the CLA](#signing-the-cla)
1414

1515
## <a name="coc"></a> Code of Conduct
16+
1617
Help us keep Scully open and inclusive. Please read and follow our [Code of Conduct][coc].
1718

1819
## <a name="question"></a> Got a Question or Problem?
@@ -30,20 +31,22 @@ To save your and our time, we will systematically close all issues that are requ
3031
If you would like to chat about the question in real-time, you can reach out via our gitter channel (Coming soon).
3132

3233
## <a name="issue"></a> Found a Bug?
34+
3335
If you find a bug in the source code, you can help us by
3436
[submitting an issue][github-issue] to our [GitHub Repository][github]. Even better, you can
3537
[submit a Pull Request](#submit-pr) with a fix.
3638

3739
## <a name="feature"></a> Missing a Feature?
38-
You can *request* a new feature by [submitting an issue](#submit-issue) to our GitHub
39-
Repository. If you would like to *implement* a new feature, please submit an issue with
40+
41+
You can _request_ a new feature by [submitting an issue](#submit-issue) to our GitHub
42+
Repository. If you would like to _implement_ a new feature, please submit an issue with
4043
a proposal for your work first, to be sure that we can use it.
4144
Please consider what kind of change it is:
4245

43-
* For a **Major Feature**, first open an issue and outline your proposal so that it can be
44-
discussed. This will also allow us to better coordinate our efforts, prevent duplication of work,
45-
and help you to craft the change so that it is successfully accepted into the project.
46-
* **Small Features** can be crafted and directly [submitted as a Pull Request](#submit-pr).
46+
- For a **Major Feature**, first open an issue and outline your proposal so that it can be
47+
discussed. This will also allow us to better coordinate our efforts, prevent duplication of work,
48+
and help you to craft the change so that it is successfully accepted into the project.
49+
- **Small Features** can be crafted and directly [submitted as a Pull Request](#submit-pr).
4750

4851
## <a name="submit"></a> Submission Guidelines
4952

@@ -61,38 +64,40 @@ Unfortunately, we are not able to investigate / fix bugs without a minimal repro
6164

6265
You can file new issues by selecting from our [new issue templates][github-choose] and filling out the issue template.
6366

64-
6567
### <a name="submit-pr"></a> Submitting a Pull Request (PR)
68+
6669
Before you submit your Pull Request (PR) consider the following guidelines:
6770

6871
1. Search [GitHub](https://github.com/scullyio/scully/pulls) for an open or closed PR
69-
that relates to your submission. You don't want to duplicate effort.
72+
that relates to your submission. You don't want to duplicate effort.
7073
1. Be sure that an issue describes the problem you're fixing, or documents the design for the feature you'd like to add.
71-
Discussing the design up front helps to ensure that we're ready to accept your work.
74+
Discussing the design up front helps to ensure that we're ready to accept your work.
7275
1. Fork the scullyio/scully repo.
7376
1. Make your changes in a new git branch:
7477

75-
```shell
76-
git checkout -b my-fix-branch master
77-
```
78+
```shell
79+
git checkout -b my-fix-branch master
80+
```
7881

7982
1. Create your patch, **including appropriate test cases**.
8083

8184
1. Commit your changes using a descriptive commit message that follows our
82-
[commit message conventions](#commit). Adherence to these conventions
83-
is necessary run the command `npm run commit` (this add all the files using `git add .`) or
84-
if you need only add some files, you can need run the command `npm run commit:select`.
85+
[commit message conventions](#commit). Adherence to these conventions
86+
is necessary run the command `npm run commit` (this add all the files using `git add .`) or
87+
if you need only add some files, you can need run the command `npm run commit:select`.
8588

8689
1. Push your branch to GitHub:
8790

88-
```shell
89-
git push origin my-fix-branch
90-
```
91+
```shell
92+
git push origin my-fix-branch
93+
```
9194

9295
1. In GitHub, send a pull request to `scully:master`.
93-
* If we suggest changes then:
94-
* Make the required updates.
95-
* Rebase your branch and force push to your GitHub repository (this will update your Pull Request):
96+
97+
- If we suggest changes then:
98+
99+
- Make the required updates.
100+
- Rebase your branch and force push to your GitHub repository (this will update your Pull Request):
96101

97102
```shell
98103
git rebase master -i
@@ -106,41 +111,41 @@ That's it! Thank you for your contribution!
106111
After your pull request is merged, you can safely delete your branch and pull the changes
107112
from the main (upstream) repository:
108113
109-
* Delete the remote branch on GitHub either through the GitHub web UI or your local shell as follows:
114+
- Delete the remote branch on GitHub either through the GitHub web UI or your local shell as follows:
110115
111-
```shell
112-
git push origin --delete my-fix-branch
113-
```
116+
```shell
117+
git push origin --delete my-fix-branch
118+
```
114119
115-
* Check out the master branch:
120+
- Check out the master branch:
116121
117-
```shell
118-
git checkout master -f
119-
```
122+
```shell
123+
git checkout master -f
124+
```
120125
121-
* Delete the local branch:
126+
- Delete the local branch:
122127
123-
```shell
124-
git branch -D my-fix-branch
125-
```
126-
127-
* Update your master with the latest upstream version:
128+
```shell
129+
git branch -D my-fix-branch
130+
```
128131
129-
```shell
130-
git pull --ff upstream master
131-
```
132+
- Update your master with the latest upstream version:
132133
134+
```shell
135+
git pull --ff upstream master
136+
```
133137
134138
## <a name="commit"></a> Commit Message Guidelines
135139
136-
We have very precise rules over how our git commit messages can be formatted. This leads to **more
140+
We have very precise rules over how our git commit messages can be formatted. This leads to **more
137141
readable messages** that are easy to follow when looking through the **project history**.
138142
139143
### Commit Message Format
140-
Each commit message consists of a **header**, a **body** and a **footer**. The header has a special
144+
145+
Each commit message consists of a **header**, a **body** and a **footer**. The header has a special
141146
format that includes a **type**, a **scope** and a **subject**:
142147
143-
_The command `npm run commit` was previously configured to use all these rules_
148+
_The command `npm run commit` was previously configured to use all these rules_
144149
145150
```
146151
<type>(<scope>): <subject>
@@ -162,46 +167,51 @@ Samples from Angular Repository: (even more [samples](https://github.com/angular
162167
```
163168
docs(changelog): update changelog to beta.5
164169
```
170+
165171
```
166172
fix(release): need to depend on latest ng-lib
167173
168174
The version in our package.json gets copied to the one we publish, and users need the latest of these.
169175
```
170176
171177
### Type
178+
172179
Must be one of the following:
173180
174-
* **build**: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
175-
* **docs**: Documentation only changes
176-
* **feat**: A new feature
177-
* **fix**: A bug fix
178-
* **perf**: A code change that improves performance
179-
* **refactor**: A code change that neither fixes a bug nor adds a feature
180-
* **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
181-
* **test**: Adding missing tests or correcting existing tests
181+
- **build**: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
182+
- **docs**: Documentation only changes
183+
- **feat**: A new feature
184+
- **fix**: A bug fix
185+
- **perf**: A code change that improves performance
186+
- **refactor**: A code change that neither fixes a bug nor adds a feature
187+
- **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
188+
- **test**: Adding missing tests or correcting existing tests
182189
183190
### Scope
191+
184192
The scope should be the name of the npm package affected (as perceived by the person reading the changelog generated from commit messages).
185193
186194
The following is the list of supported scopes:
187195
188-
* **scully**
189-
* **ng-lib**
190-
* **schematics**
191-
196+
- **scully**
197+
- **ng-lib**
198+
- **schematics**
192199
193200
### Subject
201+
194202
The subject contains a succinct description of the change:
195203
196-
* use the imperative, present tense: "change" not "changed" nor "changes"
197-
* don't capitalize the first letter
198-
* no dot (.) at the end
204+
- use the imperative, present tense: "change" not "changed" nor "changes"
205+
- don't capitalize the first letter
206+
- no dot (.) at the end
199207

200208
### Body
209+
201210
Just as in the **subject**, use the imperative, present tense: "change" not "changed" nor "changes".
202211
The body should include the motivation for the change and contrast this with previous behavior.
203212

204213
### Footer
214+
205215
The footer should contain any information about **Breaking Changes** and is also the place to
206216
reference GitHub issues that this commit **Closes**.
207217

@@ -214,7 +224,6 @@ Please sign our Contributor License Agreement (CLA) before sending pull requests
214224
- For individuals we have a [simple click-through form][cla-individual].
215225
- For corporations we'll need you to [print, sign and one of scan+email, fax or mail the form][cla-corporations].
216226

217-
218227
[coc]: https://github.com/scullyio/scully/blob/master/CODE_OF_CONDUCT.md
219228
[github]: https://github.com/scullyio/scully
220229
[github-issue]: https://github.com/scullyio/scully/issues/new?assignees=&labels=bug&template=---bug-report.md&title=

blog/page-1.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@ author: Sander Elias
44
publish date: 2019-11-26
55
description: This is the first demo page in this sample.
66
---
7+
78
# Page 1
89

910
## or, how to do interesting blog things
1011

1112
```typescript
12-
console.log('hello world')
13+
console.log('hello world');
1314
```
1415

1516
Related information [page-2](/blog/page-2)
1617

18+
# Down-under
1719

1820
[site-map](/home)
19-
20-
<!-- 06 231 449 78 Dave Vera, -->
21-

extraPlugin/extra-plugin.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
const {configValidator, routeSplit, registerPlugin} = require('../dist/scully');
22

3-
console.log(__dirname);
4-
53
const extraRoutesPlugin = (route, options) => {
64
const {createPath} = routeSplit(route);
75
if (options.numberOfPages) {

extraPlugin/tocPlugin.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const {registerPlugin, configValidator, logWarn, yellow} = require('../dist/scully');
2+
const jsdom = require('jsdom');
3+
const {JSDOM} = jsdom;
4+
5+
const tocPlugin = async (html, options) => {
6+
try {
7+
const dom = new JSDOM(html);
8+
const {window} = dom;
9+
const h1headers = window.document.querySelectorAll('h1');
10+
const h2headers = window.document.querySelectorAll('h2');
11+
const toc = [...h1headers, ...h2headers]
12+
.map(e => e.innerHTML)
13+
.map(c => `<li>${c}</li>`)
14+
.join('');
15+
const insertPoint = window.document.querySelector('main').querySelector('h1');
16+
const list = window.document.createElement('ul');
17+
list.innerHTML = toc;
18+
insertPoint.parentElement.insertBefore(list, insertPoint);
19+
return dom.serialize();
20+
} catch (e) {
21+
logWarn(`error in tocPlugin, didn't parse for route "${yellow(route.route)}"`);
22+
}
23+
// in case of failure return unchanged HTML to keep flow going
24+
return html;
25+
};
26+
27+
tocPlugin[configValidator] = async config => [];
28+
registerPlugin('render', 'toc', tocPlugin);

0 commit comments

Comments
 (0)