mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-26 22:04:32 +02:00
@@ -16,13 +16,12 @@ package dartsass
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/gohugoio/hugo/common/herrors"
|
||||
"github.com/gohugoio/hugo/common/hexec"
|
||||
"github.com/gohugoio/hugo/common/paths"
|
||||
"github.com/gohugoio/hugo/htesting"
|
||||
"github.com/gohugoio/hugo/media"
|
||||
|
||||
@@ -38,9 +37,6 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// See https://github.com/sass/dart-sass-embedded/issues/24
|
||||
// Note: This prefix must be all lower case.
|
||||
stdinPrefix = "hugostdin:"
|
||||
dartSassEmbeddedBinaryName = "dart-sass-embedded"
|
||||
)
|
||||
|
||||
@@ -76,7 +72,7 @@ func (t *transform) Transform(ctx *resources.ResourceTransformationCtx) error {
|
||||
}
|
||||
|
||||
baseDir := path.Dir(ctx.SourcePath)
|
||||
filename := stdinPrefix
|
||||
filename := dartSassStdinPrefix
|
||||
|
||||
if ctx.SourcePath != "" {
|
||||
filename += t.c.sfs.RealFilename(ctx.SourcePath)
|
||||
@@ -108,26 +104,6 @@ func (t *transform) Transform(ctx *resources.ResourceTransformationCtx) error {
|
||||
|
||||
res, err := t.c.toCSS(args, ctx.From)
|
||||
if err != nil {
|
||||
if sassErr, ok := err.(godartsass.SassError); ok {
|
||||
start := sassErr.Span.Start
|
||||
context := strings.TrimSpace(sassErr.Span.Context)
|
||||
filename, _ := urlToFilename(sassErr.Span.Url)
|
||||
if strings.HasPrefix(filename, stdinPrefix) {
|
||||
filename = filename[len(stdinPrefix):]
|
||||
}
|
||||
|
||||
offsetMatcher := func(m herrors.LineMatcher) int {
|
||||
if m.Offset+len(m.Line) >= start.Offset && strings.Contains(m.Line, context) {
|
||||
// We found the line, but return 0 to signal that we want to determine
|
||||
// the column from the error.
|
||||
return 0
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
return herrors.NewFileErrorFromFile(sassErr, filename, hugofs.Os, offsetMatcher)
|
||||
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -154,7 +130,7 @@ type importResolver struct {
|
||||
}
|
||||
|
||||
func (t importResolver) CanonicalizeURL(url string) (string, error) {
|
||||
filePath, isURL := urlToFilename(url)
|
||||
filePath, isURL := paths.UrlToFilename(url)
|
||||
var prevDir string
|
||||
var pathDir string
|
||||
if isURL {
|
||||
@@ -200,23 +176,7 @@ func (t importResolver) CanonicalizeURL(url string) (string, error) {
|
||||
}
|
||||
|
||||
func (t importResolver) Load(url string) (string, error) {
|
||||
filename, _ := urlToFilename(url)
|
||||
filename, _ := paths.UrlToFilename(url)
|
||||
b, err := afero.ReadFile(hugofs.Os, filename)
|
||||
return string(b), err
|
||||
}
|
||||
|
||||
// TODO(bep) add tests
|
||||
func urlToFilename(urls string) (string, bool) {
|
||||
u, err := url.ParseRequestURI(urls)
|
||||
if err != nil {
|
||||
return filepath.FromSlash(urls), false
|
||||
}
|
||||
p := filepath.FromSlash(u.Path)
|
||||
|
||||
if u.Host != "" {
|
||||
// C:\data\file.txt
|
||||
p = strings.ToUpper(u.Host) + ":" + p
|
||||
}
|
||||
|
||||
return p, true
|
||||
}
|
||||
|
Reference in New Issue
Block a user