mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-15 20:44:01 +02:00
Add resources.Copy
Implemented by most Resource objects, but not Page (for now). Fixes #9313
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Hugo Authors. All rights reserved.
|
||||
// Copyright 2022 The Hugo Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@@ -120,8 +120,19 @@ func (t transformerNotAvailable) Key() internal.ResourceTransformationKey {
|
||||
return t.key
|
||||
}
|
||||
|
||||
// resourceCopier is for internal use.
|
||||
type resourceCopier interface {
|
||||
cloneTo(targetPath string) resource.Resource
|
||||
}
|
||||
|
||||
// Copy copies r to the targetPath given.
|
||||
func Copy(r resource.Resource, targetPath string) resource.Resource {
|
||||
return r.(resourceCopier).cloneTo(targetPath)
|
||||
}
|
||||
|
||||
type baseResourceResource interface {
|
||||
resource.Cloner
|
||||
resourceCopier
|
||||
resource.ContentProvider
|
||||
resource.Resource
|
||||
resource.Identifier
|
||||
@@ -225,6 +236,20 @@ func (l *genericResource) Clone() resource.Resource {
|
||||
return l.clone()
|
||||
}
|
||||
|
||||
func (l *genericResource) cloneTo(targetPath string) resource.Resource {
|
||||
c := l.clone()
|
||||
|
||||
targetPath = helpers.ToSlashTrimLeading(targetPath)
|
||||
dir, file := path.Split(targetPath)
|
||||
|
||||
c.resourcePathDescriptor = &resourcePathDescriptor{
|
||||
relTargetDirFile: dirFile{dir: dir, file: file},
|
||||
}
|
||||
|
||||
return c
|
||||
|
||||
}
|
||||
|
||||
func (l *genericResource) Content() (any, error) {
|
||||
if err := l.initContent(); err != nil {
|
||||
return nil, err
|
||||
|
Reference in New Issue
Block a user