Skip to content

Commit 424cff2

Browse files
rockwotjfilipesilva
authored andcommitted
fix(deploy): Fix base href for user pages (angular#965)
* fix(deploy): Fix base href for user pages Deploying to user pages would change the base URL to something like "/angular.github.io/" instead of the correct "/" due to the URL structure for user pages. * style(lint): use single quotes for string
1 parent 67b577d commit 424cff2

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

addon/ng2/commands/github-pages-deploy.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,13 @@ module.exports = Command.extend({
162162
if (file === '.gitignore'){
163163
// don't overwrite the .gitignore file
164164
return Promise.resolve();
165-
}
165+
}
166166
return fsCopy(path.join('dist', file), path.join('.', file))
167167
})));
168168
}
169169

170170
function updateBaseHref() {
171+
if (options.userPage) return Promise.resolve();
171172
let indexHtml = path.join(root, 'index.html');
172173
return fsReadFile(indexHtml, 'utf8')
173174
.then((data) => data.replace(/<base href="\/">/g, `<base href="/${projectName}/">`))
@@ -192,7 +193,8 @@ module.exports = Command.extend({
192193
return execPromise('git remote -v')
193194
.then((stdout) => {
194195
let userName = stdout.match(/origin\s+(?:https:\/\/|git@)github\.com(?:\:|\/)([^\/]+)/m)[1].toLowerCase();
195-
ui.writeLine(chalk.green(`Deployed! Visit https://${userName}.github.io/${projectName}/`));
196+
let url = `https://${userName}.github.io/${options.userPage ? '' : (projectName + '/')}`;
197+
ui.writeLine(chalk.green(`Deployed! Visit ${url}`));
196198
ui.writeLine('Github pages might take a few minutes to show the deployed site.');
197199
});
198200
}

tests/acceptance/github-pages-deploy.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ describe('Acceptance: ng github-pages:deploy', function() {
106106
let indexHtml = path.join(process.cwd(), 'index.html');
107107
return fsReadFile(indexHtml, 'utf8');
108108
})
109-
.then((data) => expect(data.search(`<base href="/${project}/">`)).to.not.equal(-1));
109+
.then((data) => expect(data.search('<base href="/">')).to.not.equal(-1));
110110
});
111111

112112
it('should create branch if needed', function() {

0 commit comments

Comments
 (0)