Skip to content

Commit 55501ff

Browse files
authored
Merge pull request #533 from tschaub/nojekyll-cname
Add --nojekyll and --cname options
2 parents df07fd4 + 8181619 commit 55501ff

File tree

20 files changed

+169
-2
lines changed

20 files changed

+169
-2
lines changed

bin/gh-pages.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ function main(args) {
5151
.option('-g, --tag <tag>', 'add tag to commit')
5252
.option('--git <git>', 'Path to git executable', ghpages.defaults.git)
5353
.option('-t, --dotfiles', 'Include dotfiles')
54+
.option('--nojekyll', 'Add a .nojekyll file to disable Jekyll')
55+
.option(
56+
'--cname <CNAME>',
57+
'Add a CNAME file with the name of your custom domain'
58+
)
5459
.option('-r, --repo <repo>', 'URL of the repository you are pushing to')
5560
.option('-p, --depth <depth>', 'depth for clone', ghpages.defaults.depth)
5661
.option(
@@ -121,6 +126,7 @@ function main(args) {
121126
git: options.git,
122127
depth: options.depth,
123128
dotfiles: !!options.dotfiles,
129+
nojekyll: !!options.nojekyll,
124130
add: !!options.add,
125131
remove: options.remove,
126132
remote: options.remote,

lib/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ exports.publish = function publish(basePath, config, callback) {
184184
})
185185
.then((git) => {
186186
log('Copying files');
187+
if (options.nojekyll) {
188+
fs.createFileSync(path.join(git.cwd, '.nojekyll'));
189+
}
190+
if (options.cname) {
191+
fs.writeFileSync(path.join(git.cwd, 'CNAME'), options.cname);
192+
}
187193
return copy(files, basePath, path.join(git.cwd, options.dest)).then(
188194
function () {
189195
return git;

readme.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,35 @@ Example use of the `dotfiles` option:
128128
ghpages.publish('dist', {dotfiles: true}, callback);
129129
```
130130

131+
#### <a id="optionsnojekyll">options.nojekyll</a>
132+
* type: `boolean`
133+
* default: `false`
134+
135+
Write out a `.nojekyll` file to [bypass Jekyll on GitHub Pages](https://github.blog/2009-12-29-bypassing-jekyll-on-github-pages/).
136+
137+
Example use of the `nojekyll` option:
138+
139+
```js
140+
/**
141+
* The usage below will add a `.nojekyll` file to the output.
142+
*/
143+
ghpages.publish('dist', {nojekyll: true}, callback);
144+
```
145+
146+
#### <a id="optionscname">options.cname</a>
147+
* type: `string`
148+
149+
Write out a `CNAME` file with a custom domain name.
150+
151+
Example use of the `cname` option:
152+
153+
```js
154+
/**
155+
* The usage below will add a `CNAME` file to the output.
156+
*/
157+
ghpages.publish('dist', {cname: 'custom-domain.com'}, callback);
158+
```
159+
131160

132161
#### <a id="optionsadd">options.add</a>
133162
* type: `boolean`
@@ -402,10 +431,10 @@ If `gh-pages` fails, you may find that you need to manually clean up the cache d
402431

403432
### Deploying to github pages with custom domain
404433

405-
Modify the deployment line to your deploy script if you use custom domain. This will prevent the deployment from removing the domain settings in GitHub.
434+
Use the `--cname` option to create a `CNAME` file with the name of your custom domain. See [the GitHub docs](https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/managing-a-custom-domain-for-your-github-pages-site) for more detail.
406435

407436
```
408-
echo your_cutom_domain.online > ./build/CNAME && gh-pages -d build"
437+
gh-pages -d build --cname custom-domain.com"
409438
```
410439

411440
### Deploying with GitHub Actions

test/bin/gh-pages.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ describe('gh-pages', () => {
4242
dist: 'lib',
4343
config: {dotfiles: true},
4444
},
45+
{
46+
args: ['--dist', 'lib', '--nojekyll'],
47+
dist: 'lib',
48+
config: {nojekyll: true},
49+
},
4550
{
4651
args: ['--dist', 'lib', '--dest', 'target'],
4752
dist: 'lib',

test/integration/cname.spec.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const helper = require('../helper.js');
2+
const ghPages = require('../../lib/index.js');
3+
const path = require('path');
4+
5+
const fixtures = path.join(__dirname, 'fixtures');
6+
const fixtureName = 'cname';
7+
8+
beforeEach(() => {
9+
ghPages.clean();
10+
});
11+
12+
describe('the --cname option', () => {
13+
it('adds a CNAME file', (done) => {
14+
const local = path.join(fixtures, fixtureName, 'local');
15+
const expected = path.join(fixtures, fixtureName, 'expected');
16+
const branch = 'gh-pages';
17+
18+
helper.setupRemote(fixtureName, {branch}).then((url) => {
19+
const options = {
20+
repo: url,
21+
user: {
22+
name: 'User Name',
23+
24+
},
25+
cname: 'custom-domain.com',
26+
};
27+
ghPages.publish(local, options, (err) => {
28+
if (err) {
29+
return done(err);
30+
}
31+
helper
32+
.assertContentsMatch(expected, url, branch)
33+
.then(() => done())
34+
.catch(done);
35+
});
36+
});
37+
});
38+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
custom-domain.com
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World!
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World!

test/integration/fixtures/cname/remote/initial

Whitespace-only changes.

test/integration/fixtures/nojekyll-exists/expected/.nojekyll

Whitespace-only changes.

0 commit comments

Comments
 (0)