Commit 492627c9 authored by Kamil Trzcinski's avatar Kamil Trzcinski Committed by James Edwards-Jones

Fix the URL of group pages

parent c089f103
......@@ -1167,12 +1167,16 @@ class Project < ActiveRecord::Base
def pages_url
return unless Dir.exist?(public_pages_path)
host = "#{namespace.path}.#{Settings.pages.host}"
# The hostname always needs to be in downcased
# All web servers convert hostname to lowercase
host = "#{namespace.path}.#{Settings.pages.host}".downcase
# The host in URL always needs to be downcased
url = Gitlab.config.pages.url.sub(/^https?:\/\//) do |prefix|
"#{prefix}#{namespace.path}."
end
end.downcase
# If the project path is the same as host, leave the short version
# If the project path is the same as host, we serve it as group page
return url if host == path
"#{url}/#{path}"
......
......@@ -45,6 +45,14 @@ URL it will be accessible.
| Specific project under a user's page | `walter/area51` | `https://walter.gitlab.io/area51` |
| Specific project under a group's page | `therug/welovecats` | `https://therug.gitlab.io/welovecats` |
## Group pages
You can create a group page in context of your group.
The project for group page must be written in lower.
If you have a group `TheRug` and pages are hosted under `Example.com` in order to create a group page
create a new project named `therug.example.com`.
## Enable the pages feature in your project
The GitLab Pages feature needs to be explicitly enabled for each project
......
......@@ -1845,4 +1845,37 @@ describe Project, models: true do
def enable_lfs
allow(Gitlab.config.lfs).to receive(:enabled).and_return(true)
end
describe :pages_url do
let(:group) { create :group, name: group_name }
let(:project) { create :empty_project, namespace: group, name: project_name }
let(:domain) { 'Example.com' }
subject { project.pages_url }
before do
FileUtils.mkdir_p(project.public_pages_path)
allow(Settings.pages).to receive(:host).and_return(domain)
allow(Gitlab.config.pages).to receive(:url).and_return('http://example.com')
end
after do
FileUtils.rmdir(project.public_pages_path)
end
context 'group page' do
let(:group_name) { 'Group' }
let(:project_name) { 'group.example.com' }
it { is_expected.to eq("http://group.example.com") }
end
context 'project page' do
let(:group_name) { 'Group' }
let(:project_name) { 'Project' }
it { is_expected.to eq("http://group.example.com/project") }
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment