mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-16 20:53:59 +02:00
Fix sub-folder baseURL handling for Page resources
I.e. images etc. Fixes #4228
This commit is contained in:
@@ -26,6 +26,10 @@ import (
|
||||
type PathSpec struct {
|
||||
BaseURL
|
||||
|
||||
// If the baseURL contains a base path, e.g. https://example.com/docs, then "/docs" will be the BasePath.
|
||||
// This will not be set if canonifyURLs is enabled.
|
||||
BasePath string
|
||||
|
||||
disablePathToLower bool
|
||||
removePathAccents bool
|
||||
uglyURLs bool
|
||||
@@ -124,6 +128,13 @@ func NewPathSpec(fs *hugofs.Fs, cfg config.Provider) (*PathSpec, error) {
|
||||
ProcessingStats: NewProcessingStats(lang),
|
||||
}
|
||||
|
||||
if !ps.canonifyURLs {
|
||||
basePath := ps.BaseURL.url.Path
|
||||
if basePath != "" && basePath != "/" {
|
||||
ps.BasePath = basePath
|
||||
}
|
||||
}
|
||||
|
||||
publishDir := ps.AbsPathify(cfg.GetString("publishDir")) + FilePathSeparator
|
||||
// If root, remove the second '/'
|
||||
if publishDir == "//" {
|
||||
|
@@ -319,12 +319,11 @@ func AddContextRoot(baseURL, relativePath string) string {
|
||||
// If canonifyURLs is set, we will globally prepend the absURL with any sub-folder,
|
||||
// so avoid doing anything here to avoid getting double paths.
|
||||
func (p *PathSpec) PrependBasePath(rel string) string {
|
||||
basePath := p.BaseURL.url.Path
|
||||
if !p.canonifyURLs && basePath != "" && basePath != "/" {
|
||||
if p.BasePath != "" {
|
||||
rel = filepath.ToSlash(rel)
|
||||
// Need to prepend any path from the baseURL
|
||||
hadSlash := strings.HasSuffix(rel, "/")
|
||||
rel = path.Join(basePath, rel)
|
||||
rel = path.Join(p.BasePath, rel)
|
||||
if hadSlash {
|
||||
rel += "/"
|
||||
}
|
||||
|
Reference in New Issue
Block a user