Skip to content

Commit b1e65e7

Browse files
TimKolbergerSaraVieira
authored andcommitted
Add configuration option to add a path prefix (#18)
* Add path prefix configuration * Improve configuration hint * Mention env var in Readme * Add @TimKolberger as a contributor * Add all-contributors-cli as dev dependency * Add yarn lock integrity checks * Rename function to be more specific * Add logo src to integration test
1 parent 492cd16 commit b1e65e7

12 files changed

+136
-16
lines changed

.all-contributorsrc

+9
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@
6464
"contributions": [
6565
"code"
6666
]
67+
},
68+
{
69+
"login": "TimKolberger",
70+
"name": "timkolberger",
71+
"avatar_url": "https://avatars2.githubusercontent.com/u/16899513?v=4",
72+
"profile": "https://github.com/TimKolberger",
73+
"contributions": [
74+
"code"
75+
]
6776
}
6877
]
6978
}

Deployment.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,19 @@ After that pick and domain and done 🎉
6363

6464
## Gitlab Pages
6565

66-
// Todo
66+
To deploy to Gitlab Pages add a new job with the title _pages_ in your `.gitlab-ci.yml` configuration file.
67+
Gitlab Pages hosts your static files at https://<group-or-user-name>.gitlab.io/<project-name>.
68+
You can use the `PATH_PREFIX` environment variable to configure your fiddly build.
69+
🎉
70+
71+
```yml
72+
pages:
73+
image: node
74+
script:
75+
- PATH_PREFIX="/$CI_PROJECT_NAME" npx fiddly
76+
artifacts:
77+
paths:
78+
- public
79+
only:
80+
- master
81+
```

Readme.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ It can contains the following options:
7171
| styles | {} | Styles to apply to the page. Object or path to css/scss file |
7272
| additionalFiles | [] | Any other pages to create. It expects an array of paths of markdown files |
7373
| repo | null | Link to point the github corner |
74+
| pathPrefix | Environment var PATH_PREFIX or '/' | Host your fiddly files at e.g. /my-fiddly-project |
7475

7576
<!-- markdownlint-enable -->
7677

@@ -167,9 +168,8 @@ You can run this by using the `lint` command
167168
<!-- markdownlint-disable -->
168169
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
169170
<!-- prettier-ignore -->
170-
| [<img src="https://avatars0.githubusercontent.com/u/1051509?v=4" width="100px;"/><br /><sub><b>Sara Vieira</b></sub>](http://iamsaravieira.com)<br />[💻](https://github.com/SaraVieira/fiddly/commits?author=SaraVieira "Code") [🎨](#design-SaraVieira "Design") [🤔](#ideas-SaraVieira "Ideas, Planning, & Feedback") | [<img src="https://avatars2.githubusercontent.com/u/4772980?v=4" width="100px;"/><br /><sub><b>Bruno Scheufler</b></sub>](https://brunoscheufler.com)<br />[💻](https://github.com/SaraVieira/fiddly/commits?author=BrunoScheufler "Code") | [<img src="https://avatars0.githubusercontent.com/u/1863771?v=4" width="100px;"/><br /><sub><b>Siddharth Kshetrapal</b></sub>](https://sid.studio)<br />[💻](https://github.com/SaraVieira/fiddly/commits?author=siddharthkp "Code") | [<img src="https://avatars3.githubusercontent.com/u/1479215?v=4" width="100px;"/><br /><sub><b>Jamon Holmgren</b></sub>](https://jamonholmgren.com)<br />[💻](https://github.com/SaraVieira/fiddly/commits?author=jamonholmgren "Code") | [<img src="https://avatars0.githubusercontent.com/u/1695613?v=4" width="100px;"/><br /><sub><b>Timothy</b></sub>](http://timothy.is)<br />[💻](https://github.com/SaraVieira/fiddly/commits?author=timothyis "Code") | [<img src="https://avatars2.githubusercontent.com/u/13808724?v=4" width="100px;"/><br /><sub><b>Andrew Cherniavskii</b></sub>](https://github.com/cherniavskii)<br />[💻](https://github.com/SaraVieira/fiddly/commits?author=cherniavskii "Code") |
171-
| :---: | :---: | :---: | :---: | :---: | :---: |
172-
171+
| [<img src="https://avatars0.githubusercontent.com/u/1051509?v=4" width="100px;"/><br /><sub><b>Sara Vieira</b></sub>](http://iamsaravieira.com)<br />[💻](https://github.com/SaraVieira/fiddly/commits?author=SaraVieira "Code") [🎨](#design-SaraVieira "Design") [🤔](#ideas-SaraVieira "Ideas, Planning, & Feedback") | [<img src="https://avatars2.githubusercontent.com/u/4772980?v=4" width="100px;"/><br /><sub><b>Bruno Scheufler</b></sub>](https://brunoscheufler.com)<br />[💻](https://github.com/SaraVieira/fiddly/commits?author=BrunoScheufler "Code") | [<img src="https://avatars0.githubusercontent.com/u/1863771?v=4" width="100px;"/><br /><sub><b>Siddharth Kshetrapal</b></sub>](https://sid.studio)<br />[💻](https://github.com/SaraVieira/fiddly/commits?author=siddharthkp "Code") | [<img src="https://avatars3.githubusercontent.com/u/1479215?v=4" width="100px;"/><br /><sub><b>Jamon Holmgren</b></sub>](https://jamonholmgren.com)<br />[💻](https://github.com/SaraVieira/fiddly/commits?author=jamonholmgren "Code") | [<img src="https://avatars0.githubusercontent.com/u/1695613?v=4" width="100px;"/><br /><sub><b>Timothy</b></sub>](http://timothy.is)<br />[💻](https://github.com/SaraVieira/fiddly/commits?author=timothyis "Code") | [<img src="https://avatars2.githubusercontent.com/u/13808724?v=4" width="100px;"/><br /><sub><b>Andrew Cherniavskii</b></sub>](https://github.com/cherniavskii)<br />[💻](https://github.com/SaraVieira/fiddly/commits?author=cherniavskii "Code") | [<img src="https://avatars2.githubusercontent.com/u/16899513?v=4" width="100px;"/><br /><sub><b>timkolberger</b></sub>](https://github.com/TimKolberger)<br />[💻](https://github.com/SaraVieira/fiddly/commits?author=TimKolberger "Code") |
172+
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
173173
<!-- ALL-CONTRIBUTORS-LIST:END -->
174174
<!-- ALL-CONTRIBUTORS-LIST: START - Do not remove or modify this section -->
175175
<!-- ALL-CONTRIBUTORS-LIST:END -->

__tests__/cli-integration.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,21 @@ test('Image test', async () => {
138138
filesystem.remove('public')
139139
process.chdir(prevDir)
140140
})
141+
142+
test('Prefixes logo and additional file paths', async () => {
143+
const prevDir = process.cwd()
144+
145+
process.chdir('./__tests__/test-readme/path-prefix')
146+
147+
const output = await cli()
148+
149+
expect(output).toContain(success)
150+
expect(filesystem.exists('public/index.html')).toBeTruthy()
151+
const html = filesystem.read('public/index.html')
152+
153+
expect(html).toContain(`href="/fiddly-rocks/one"`)
154+
expect(html).toContain(`src="/fiddly-rocks/logo.png"`)
155+
156+
filesystem.remove('public')
157+
process.chdir(prevDir)
158+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"additionalFiles": ["./one.md"],
3+
"pathPrefix": "/fiddly-rocks",
4+
"logo": "logo.png"
5+
}
17.3 KB
Loading
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Just a test
2+
3+
Testing a thing.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"to-css": "^1.2.1"
5656
},
5757
"devDependencies": {
58+
"all-contributors-cli": "^5.5.0",
5859
"eslint": "^5.11.0",
5960
"eslint-config-standard": "^12.0.0",
6061
"eslint-plugin-import": "^2.14.0",

src/commands/fiddly.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ const defaultOptions = {
4343
favicon: '',
4444
additionalFiles: [],
4545
homepage: null,
46-
repo: null
46+
repo: null,
47+
pathPrefix: `${process.env.PATH_PREFIX || ''}`
4748
}
4849

4950
module.exports = {
@@ -93,6 +94,9 @@ module.exports = {
9394

9495
// HTML
9596

97+
// Add trailing slash if missing
98+
options.pathPrefix = options.pathPrefix.replace(/\/?$/, '/')
99+
96100
// Check for `options.file`, if null, check if a default file exists, or error
97101
if (options.file === null) {
98102
options.additionalFiles.unshift(

src/utils/header.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,27 @@ module.exports = (options, name, pages) => {
1111
: (file.split('/')[file.split('/').length - 1] || '').split('.md')[0]
1212
}
1313

14+
const absolutePath = path => `${options.pathPrefix}${path}`
15+
16+
const fileHref = file =>
17+
fileName(file) === 'Home' ? '' : fileName(file).toLowerCase()
18+
1419
return options && !options.noHeader
1520
? `<header>${name ? `<h1>${name}</h1>` : ''}${
1621
options.logo !== ''
17-
? `<img class="logo" src="${options.logo}" alt="${name} logo" />`
22+
? `<img class="logo" src="${absolutePath(
23+
options.logo
24+
)}" alt="${name} logo" />`
1825
: ''
1926
}
2027
${
2128
pages.length > 1
2229
? `<nav><ul>${pages
2330
.map(
2431
page =>
25-
`<li><a href="/${
26-
fileName(page) === 'Home'
27-
? ''
28-
: fileName(page).toLowerCase()
29-
}">${capitalize(fileName(page))}</a></li>`
32+
`<li><a href="${absolutePath(fileHref(page))}">${capitalize(
33+
fileName(page)
34+
)}</a></li>`
3035
)
3136
.join('')}</ul></nav>`
3237
: ''

yarn.lock

+64-5
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@ ajv@^6.5.3, ajv@^6.5.5, ajv@^6.6.1:
8989
json-schema-traverse "^0.4.1"
9090
uri-js "^4.2.2"
9191

92+
all-contributors-cli@^5.5.0:
93+
version "5.5.0"
94+
resolved "https://registry.yarnpkg.com/all-contributors-cli/-/all-contributors-cli-5.5.0.tgz#e96219a7dab53f2e7303ad0d6f0743113c4b9171"
95+
integrity sha512-dN2Y6IMjRgArjPyCTTuOVw0AGei7UnSExIkcTq/TQVaPk46IcERcKH0gWal0LlyJ276Wa4g2XWMMtNh5xtd8xw==
96+
dependencies:
97+
async "^2.0.0-rc.1"
98+
chalk "^2.3.0"
99+
inquirer "^4.0.0"
100+
lodash "^4.11.2"
101+
pify "^3.0.0"
102+
request "^2.72.0"
103+
yargs "^10.0.3"
104+
92105
amdefine@>=0.0.4:
93106
version "1.0.1"
94107
resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5"
@@ -538,7 +551,7 @@ async-limiter@~1.0.0:
538551
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.0.tgz#78faed8c3d074ab81f22b4e985d79e8738f720f8"
539552
integrity sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==
540553

541-
async@^2.1.4, async@^2.5.0:
554+
async@^2.0.0-rc.1, async@^2.1.4, async@^2.5.0:
542555
version "2.6.1"
543556
resolved "https://registry.yarnpkg.com/async/-/async-2.6.1.tgz#b245a23ca71930044ec53fa46aa00a3e87c6a610"
544557
integrity sha512-fNEiL2+AZt6AlAw/29Cr0UDe4sRAHCpEHh54WMz+Bb7QfNcFw4h3loofyJpLeQs4Yx7yuqu/2dLgM5hKOs6HlQ==
@@ -1140,7 +1153,7 @@ chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3:
11401153
strip-ansi "^3.0.0"
11411154
supports-color "^2.0.0"
11421155

1143-
chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.1, chalk@^2.4.1:
1156+
chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.3.1, chalk@^2.4.1:
11441157
version "2.4.1"
11451158
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.1.tgz#18c49ab16a037b6eb0152cc83e3471338215b66e"
11461159
integrity sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ==
@@ -1149,6 +1162,11 @@ chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.1, chalk@^2.4.1:
11491162
escape-string-regexp "^1.0.5"
11501163
supports-color "^5.3.0"
11511164

1165+
chardet@^0.4.0:
1166+
version "0.4.2"
1167+
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.4.2.tgz#b5473b33dc97c424e5d98dc87d55d4d8a29c8bf2"
1168+
integrity sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I=
1169+
11521170
chardet@^0.7.0:
11531171
version "0.7.0"
11541172
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e"
@@ -2464,6 +2482,15 @@ extend@^3.0.0, extend@~3.0.2:
24642482
resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.2.tgz#f8b1136b4071fbd8eb140aff858b1019ec2915fa"
24652483
integrity sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==
24662484

2485+
external-editor@^2.1.0:
2486+
version "2.2.0"
2487+
resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-2.2.0.tgz#045511cfd8d133f3846673d1047c154e214ad3d5"
2488+
integrity sha512-bSn6gvGxKt+b7+6TKEv1ZycHleA7aHhRHyAqJyp5pbUFuYYNIzpZnQDk7AsYckyWdEnTeAnay0aCy2aV6iTk9A==
2489+
dependencies:
2490+
chardet "^0.4.0"
2491+
iconv-lite "^0.4.17"
2492+
tmp "^0.0.33"
2493+
24672494
external-editor@^3.0.0:
24682495
version "3.0.3"
24692496
resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-3.0.3.tgz#5866db29a97826dbe4bf3afd24070ead9ea43a27"
@@ -3391,7 +3418,7 @@ http-signature@~1.2.0:
33913418
jsprim "^1.2.2"
33923419
sshpk "^1.7.0"
33933420

3394-
[email protected], iconv-lite@^0.4.24, iconv-lite@^0.4.4:
3421+
[email protected], iconv-lite@^0.4.17, iconv-lite@^0.4.24, iconv-lite@^0.4.4:
33953422
version "0.4.24"
33963423
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
33973424
integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==
@@ -3517,6 +3544,26 @@ ini@^1.3.4, ini@~1.3.0:
35173544
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927"
35183545
integrity sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==
35193546

3547+
inquirer@^4.0.0:
3548+
version "4.0.2"
3549+
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-4.0.2.tgz#cc678b4cbc0e183a3500cc63395831ec956ab0a3"
3550+
integrity sha512-+f3qDNeZpkhFJ61NBA9jXDrGGhoQuqfEum9A681c9oHoIbGgVqjogKynjB/vNVP+nVu9w3FbFQ35c0ibU0MaIQ==
3551+
dependencies:
3552+
ansi-escapes "^3.0.0"
3553+
chalk "^2.0.0"
3554+
cli-cursor "^2.1.0"
3555+
cli-width "^2.0.0"
3556+
external-editor "^2.1.0"
3557+
figures "^2.0.0"
3558+
lodash "^4.3.0"
3559+
mute-stream "0.0.7"
3560+
run-async "^2.2.0"
3561+
rx-lite "^4.0.8"
3562+
rx-lite-aggregates "^4.0.8"
3563+
string-width "^2.1.0"
3564+
strip-ansi "^4.0.0"
3565+
through "^2.3.6"
3566+
35203567
inquirer@^6.1.0:
35213568
version "6.2.1"
35223569
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-6.2.1.tgz#9943fc4882161bdb0b0c9276769c75b32dbfcd52"
@@ -4792,7 +4839,7 @@ lodash.upperfirst@^4.3.1:
47924839
resolved "https://registry.yarnpkg.com/lodash.upperfirst/-/lodash.upperfirst-4.3.1.tgz#1365edf431480481ef0d1c68957a5ed99d49f7ce"
47934840
integrity sha1-E2Xt9DFIBIHvDRxolXpe2Z1J984=
47944841

4795-
lodash@^4.0.0, lodash@^4.13.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5, lodash@~4.17.10:
4842+
lodash@^4.0.0, lodash@^4.11.2, lodash@^4.13.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.3.0, lodash@~4.17.10:
47964843
version "4.17.11"
47974844
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
47984845
integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==
@@ -6465,7 +6512,7 @@ request-promise-native@^1.0.5:
64656512
stealthy-require "^1.1.0"
64666513
tough-cookie ">=2.3.3"
64676514

6468-
request@^2.87.0, request@^2.88.0:
6515+
request@^2.72.0, request@^2.87.0, request@^2.88.0:
64696516
version "2.88.0"
64706517
resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef"
64716518
integrity sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg==
@@ -6582,6 +6629,18 @@ run-async@^2.2.0:
65826629
dependencies:
65836630
is-promise "^2.1.0"
65846631

6632+
rx-lite-aggregates@^4.0.8:
6633+
version "4.0.8"
6634+
resolved "https://registry.yarnpkg.com/rx-lite-aggregates/-/rx-lite-aggregates-4.0.8.tgz#753b87a89a11c95467c4ac1626c4efc4e05c67be"
6635+
integrity sha1-dTuHqJoRyVRnxKwWJsTvxOBcZ74=
6636+
dependencies:
6637+
rx-lite "*"
6638+
6639+
rx-lite@*, rx-lite@^4.0.8:
6640+
version "4.0.8"
6641+
resolved "https://registry.yarnpkg.com/rx-lite/-/rx-lite-4.0.8.tgz#0b1e11af8bc44836f04a6407e92da42467b79444"
6642+
integrity sha1-Cx4Rr4vESDbwSmQH6S2kJGe3lEQ=
6643+
65856644
rxjs@^6.1.0:
65866645
version "6.3.3"
65876646
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.3.3.tgz#3c6a7fa420e844a81390fb1158a9ec614f4bad55"

0 commit comments

Comments
 (0)