mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
parent
c782ebd89c
commit
f210188da3
11 changed files with 260 additions and 71 deletions
73
.github/workflows/test-dart-sass-v1.yml
vendored
Normal file
73
.github/workflows/test-dart-sass-v1.yml
vendored
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
pull_request:
|
||||||
|
name: TestDartSassV1
|
||||||
|
env:
|
||||||
|
GOPROXY: https://proxy.golang.org
|
||||||
|
GO111MODULE: on
|
||||||
|
DART_SASS_VERSION: 1.62.1
|
||||||
|
DART_SASS_SHA_LINUX: 3574da75a7322a539034648b8ff84ff2cca162eb924d72b663d718cd3936f075
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
go-version: [1.20.x]
|
||||||
|
os: [ubuntu-latest]
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab
|
||||||
|
- name: Install Go
|
||||||
|
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753
|
||||||
|
with:
|
||||||
|
go-version: ${{ matrix.go-version }}
|
||||||
|
check-latest: true
|
||||||
|
cache: true
|
||||||
|
cache-dependency-path: |
|
||||||
|
**/go.sum
|
||||||
|
**/go.mod
|
||||||
|
- name: Install Ruby
|
||||||
|
uses: ruby/setup-ruby@ee2113536afb7f793eed4ce60e8d3b26db912da4
|
||||||
|
with:
|
||||||
|
ruby-version: '2.7'
|
||||||
|
bundler-cache: true #
|
||||||
|
- name: Install Python
|
||||||
|
uses: actions/setup-python@3105fb18c05ddd93efea5f9e0bef7a03a6e9e7df
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
- name: Install Mage
|
||||||
|
run: go install github.com/magefile/mage@v1.15.0
|
||||||
|
- name: Install asciidoctor
|
||||||
|
uses: reitzig/actions-asciidoctor@7570212ae20b63653481675fb1ff62d1073632b0
|
||||||
|
- name: Install docutils
|
||||||
|
run: |
|
||||||
|
pip install docutils
|
||||||
|
rst2html.py --version
|
||||||
|
- if: matrix.os == 'ubuntu-latest'
|
||||||
|
name: Install pandoc on Linux
|
||||||
|
run: |
|
||||||
|
sudo apt-get update -y
|
||||||
|
sudo apt-get install -y pandoc
|
||||||
|
- if: matrix.os == 'macos-latest'
|
||||||
|
run: |
|
||||||
|
brew install pandoc
|
||||||
|
- if: matrix.os == 'windows-latest'
|
||||||
|
run: |
|
||||||
|
Choco-Install -PackageName pandoc
|
||||||
|
- run: pandoc -v
|
||||||
|
- name: Install dart-sass-embedded Linux
|
||||||
|
run: |
|
||||||
|
echo "Install Dart Sass version ${DART_SASS_VERSION} ..."
|
||||||
|
curl -LJO "https://github.com/sass/dart-sass-embedded/releases/download/${DART_SASS_VERSION}/sass_embedded-${DART_SASS_VERSION}-linux-x64.tar.gz";
|
||||||
|
echo "${DART_SASS_SHA_LINUX} sass_embedded-${DART_SASS_VERSION}-linux-x64.tar.gz" | sha256sum -c;
|
||||||
|
tar -xvf "sass_embedded-${DART_SASS_VERSION}-linux-x64.tar.gz";
|
||||||
|
echo "$GITHUB_WORKSPACE/sass_embedded/" >> $GITHUB_PATH
|
||||||
|
- name: Check
|
||||||
|
run: |
|
||||||
|
dart-sass-embedded --version
|
||||||
|
mage -v check;
|
||||||
|
env:
|
||||||
|
HUGO_BUILD_TAGS: extended
|
40
.github/workflows/test.yml
vendored
40
.github/workflows/test.yml
vendored
|
@ -6,17 +6,17 @@ name: Test
|
||||||
env:
|
env:
|
||||||
GOPROXY: https://proxy.golang.org
|
GOPROXY: https://proxy.golang.org
|
||||||
GO111MODULE: on
|
GO111MODULE: on
|
||||||
DART_SASS_VERSION: 1.56.2
|
SASS_VERSION: 1.63.2
|
||||||
DART_SASS_SHA_LINUX: 9e4f455f7b8619959d7878af2862383be58392eb963a14ff87cc512c03701e2a
|
DART_SASS_SHA_LINUX: 3ea33c95ad5c35fda6e9a0956199eef38a398f496cfb8750e02479d7d1dd42af
|
||||||
DART_SASS_SHA_MACOS: 5992e979e2c30ec363f8e338822bb2b4443c74232b3340501a76180f5652cb09
|
DART_SASS_SHA_MACOS: 11c70f259836b250b44a9cb57fed70e030f21f45069b467d371685855f1eb4f0
|
||||||
DART_SASS_SHA_WINDOWS: 8d3d9117c54840e3e6a4919e43acf75ea52f28a64fc87a8e29d80ec72ee36cfb
|
DART_SASS_SHA_WINDOWS: cd8cd36a619dd8e27f93d3186c52d70eb7d69472aa6c85f5094b29693e773f64
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
go-version: [1.19.x, 1.20.x]
|
go-version: [1.19.x,1.20.x]
|
||||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
|
@ -66,29 +66,31 @@ jobs:
|
||||||
- if: matrix.os == 'ubuntu-latest'
|
- if: matrix.os == 'ubuntu-latest'
|
||||||
name: Install dart-sass-embedded Linux
|
name: Install dart-sass-embedded Linux
|
||||||
run: |
|
run: |
|
||||||
echo "Install Dart Sass version ${DART_SASS_VERSION} ..."
|
echo "Install Dart Sass version ${SASS_VERSION} ..."
|
||||||
curl -LJO "https://github.com/sass/dart-sass-embedded/releases/download/${DART_SASS_VERSION}/sass_embedded-${DART_SASS_VERSION}-linux-x64.tar.gz";
|
curl -LJO "https://github.com/sass/dart-sass/releases/download/${SASS_VERSION}/dart-sass-${SASS_VERSION}-linux-x64.tar.gz";
|
||||||
echo "${DART_SASS_SHA_LINUX} sass_embedded-${DART_SASS_VERSION}-linux-x64.tar.gz" | sha256sum -c;
|
echo "${DART_SASS_SHA_LINUX} dart-sass-${SASS_VERSION}-linux-x64.tar.gz" | sha256sum -c;
|
||||||
tar -xvf "sass_embedded-${DART_SASS_VERSION}-linux-x64.tar.gz";
|
tar -xvf "dart-sass-${SASS_VERSION}-linux-x64.tar.gz";
|
||||||
echo "$GITHUB_WORKSPACE/sass_embedded/" >> $GITHUB_PATH
|
echo "$GOBIN"
|
||||||
|
echo "$GITHUB_WORKSPACE/dart-sass/" >> $GITHUB_PATH
|
||||||
- if: matrix.os == 'macos-latest'
|
- if: matrix.os == 'macos-latest'
|
||||||
name: Install dart-sass-embedded MacOS
|
name: Install dart-sass-embedded MacOS
|
||||||
run: |
|
run: |
|
||||||
echo "Install Dart Sass version ${DART_SASS_VERSION} ..."
|
echo "Install Dart Sass version ${SASS_VERSION} ..."
|
||||||
curl -LJO "https://github.com/sass/dart-sass-embedded/releases/download/${DART_SASS_VERSION}/sass_embedded-${DART_SASS_VERSION}-macos-x64.tar.gz";
|
curl -LJO "https://github.com/sass/dart-sass/releases/download/${SASS_VERSION}/dart-sass-${SASS_VERSION}-macos-x64.tar.gz";
|
||||||
echo "${DART_SASS_SHA_MACOS} sass_embedded-${DART_SASS_VERSION}-macos-x64.tar.gz" | shasum -a 256 -c;
|
echo "${DART_SASS_SHA_MACOS} dart-sass-${SASS_VERSION}-macos-x64.tar.gz" | shasum -a 256 -c;
|
||||||
tar -xvf "sass_embedded-${DART_SASS_VERSION}-macos-x64.tar.gz";
|
tar -xvf "dart-sass-${SASS_VERSION}-macos-x64.tar.gz";
|
||||||
echo "$GITHUB_WORKSPACE/sass_embedded/" >> $GITHUB_PATH
|
echo "$GITHUB_WORKSPACE/dart-sass/" >> $GITHUB_PATH
|
||||||
- if: matrix.os == 'windows-latest'
|
- if: matrix.os == 'windows-latest'
|
||||||
name: Install dart-sass-embedded Windows
|
name: Install dart-sass-embedded Windows
|
||||||
run: |
|
run: |
|
||||||
echo "Install Dart Sass version ${env:DART_SASS_VERSION} ..."
|
echo "Install Dart Sass version ${env:SASS_VERSION} ..."
|
||||||
curl -LJO "https://github.com/sass/dart-sass-embedded/releases/download/${env:DART_SASS_VERSION}/sass_embedded-${env:DART_SASS_VERSION}-windows-x64.zip";
|
curl -LJO "https://github.com/sass/dart-sass/releases/download/${env:SASS_VERSION}/dart-sass-${env:SASS_VERSION}-windows-x64.zip";
|
||||||
Expand-Archive -Path "sass_embedded-${env:DART_SASS_VERSION}-windows-x64.zip" -DestinationPath .;
|
Expand-Archive -Path "dart-sass-${env:SASS_VERSION}-windows-x64.zip" -DestinationPath .;
|
||||||
echo "$env:GITHUB_WORKSPACE/sass_embedded/" | Out-File -FilePath $Env:GITHUB_PATH -Encoding utf-8 -Append
|
echo "$env:GITHUB_WORKSPACE/dart-sass/" | Out-File -FilePath $Env:GITHUB_PATH -Encoding utf-8 -Append
|
||||||
- if: matrix.os != 'windows-latest'
|
- if: matrix.os != 'windows-latest'
|
||||||
name: Check
|
name: Check
|
||||||
run: |
|
run: |
|
||||||
|
sass --version;
|
||||||
mage -v check;
|
mage -v check;
|
||||||
env:
|
env:
|
||||||
HUGO_BUILD_TAGS: extended
|
HUGO_BUILD_TAGS: extended
|
||||||
|
|
|
@ -15,11 +15,14 @@ package herrors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
|
godartsassv1 "github.com/bep/godartsass"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/bep/godartsass"
|
"github.com/bep/godartsass/v2"
|
||||||
"github.com/bep/golibsass/libsass/libsasserrors"
|
"github.com/bep/golibsass/libsass/libsasserrors"
|
||||||
"github.com/gohugoio/hugo/common/paths"
|
"github.com/gohugoio/hugo/common/paths"
|
||||||
"github.com/gohugoio/hugo/common/text"
|
"github.com/gohugoio/hugo/common/text"
|
||||||
|
@ -145,6 +148,8 @@ func (e *fileError) causeString() string {
|
||||||
// Avoid repeating the file info in the error message.
|
// Avoid repeating the file info in the error message.
|
||||||
case godartsass.SassError:
|
case godartsass.SassError:
|
||||||
return v.Message
|
return v.Message
|
||||||
|
case godartsassv1.SassError:
|
||||||
|
return v.Message
|
||||||
case libsasserrors.Error:
|
case libsasserrors.Error:
|
||||||
return v.Message
|
return v.Message
|
||||||
default:
|
default:
|
||||||
|
@ -385,6 +390,13 @@ func extractPosition(e error) (pos text.Position) {
|
||||||
pos.Filename = filename
|
pos.Filename = filename
|
||||||
pos.Offset = start.Offset
|
pos.Offset = start.Offset
|
||||||
pos.ColumnNumber = start.Column
|
pos.ColumnNumber = start.Column
|
||||||
|
case godartsassv1.SassError:
|
||||||
|
span := v.Span
|
||||||
|
start := span.Start
|
||||||
|
filename, _ := paths.UrlToFilename(span.Url)
|
||||||
|
pos.Filename = filename
|
||||||
|
pos.Offset = start.Offset
|
||||||
|
pos.ColumnNumber = start.Column
|
||||||
case libsasserrors.Error:
|
case libsasserrors.Error:
|
||||||
pos.Filename = v.File
|
pos.Filename = v.File
|
||||||
pos.LineNumber = v.Line
|
pos.LineNumber = v.Line
|
||||||
|
|
|
@ -22,9 +22,13 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
godartsassv1 "github.com/bep/godartsass"
|
||||||
|
"github.com/mitchellh/mapstructure"
|
||||||
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bep/godartsass"
|
"github.com/bep/godartsass/v2"
|
||||||
"github.com/gohugoio/hugo/common/hexec"
|
"github.com/gohugoio/hugo/common/hexec"
|
||||||
"github.com/gohugoio/hugo/hugofs/files"
|
"github.com/gohugoio/hugo/hugofs/files"
|
||||||
|
|
||||||
|
@ -238,7 +242,10 @@ func GetDependencyListNonGo() []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
if dartSass := dartSassVersion(); dartSass.ProtocolVersion != "" {
|
if dartSass := dartSassVersion(); dartSass.ProtocolVersion != "" {
|
||||||
const dartSassPath = "github.com/sass/dart-sass-embedded"
|
var dartSassPath = "github.com/sass/dart-sass-embedded"
|
||||||
|
if IsDartSassV2() {
|
||||||
|
dartSassPath = "github.com/sass/dart-sass"
|
||||||
|
}
|
||||||
deps = append(deps,
|
deps = append(deps,
|
||||||
formatDep(dartSassPath+"/protocol", dartSass.ProtocolVersion),
|
formatDep(dartSassPath+"/protocol", dartSass.ProtocolVersion),
|
||||||
formatDep(dartSassPath+"/compiler", dartSass.CompilerVersion),
|
formatDep(dartSassPath+"/compiler", dartSass.CompilerVersion),
|
||||||
|
@ -283,11 +290,46 @@ type Dependency struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func dartSassVersion() godartsass.DartSassVersion {
|
func dartSassVersion() godartsass.DartSassVersion {
|
||||||
// This is also duplicated in the dartsass package.
|
if DartSassBinaryName == "" {
|
||||||
const dartSassEmbeddedBinaryName = "dart-sass-embedded"
|
|
||||||
if !hexec.InPath(dartSassEmbeddedBinaryName) {
|
|
||||||
return godartsass.DartSassVersion{}
|
return godartsass.DartSassVersion{}
|
||||||
}
|
}
|
||||||
v, _ := godartsass.Version(dartSassEmbeddedBinaryName)
|
if IsDartSassV2() {
|
||||||
|
v, _ := godartsass.Version(DartSassBinaryName)
|
||||||
return v
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
v, _ := godartsassv1.Version(DartSassBinaryName)
|
||||||
|
var vv godartsass.DartSassVersion
|
||||||
|
mapstructure.WeakDecode(v, &vv)
|
||||||
|
return vv
|
||||||
|
}
|
||||||
|
|
||||||
|
// DartSassBinaryName is the name of the Dart Sass binary to use.
|
||||||
|
// TODO(beop) find a better place for this.
|
||||||
|
var DartSassBinaryName string
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
DartSassBinaryName = os.Getenv("DART_SASS_BINARY")
|
||||||
|
if DartSassBinaryName == "" {
|
||||||
|
for _, name := range dartSassBinaryNamesV2 {
|
||||||
|
if hexec.InPath(name) {
|
||||||
|
DartSassBinaryName = name
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if DartSassBinaryName == "" {
|
||||||
|
if hexec.InPath(dartSassBinaryNameV1) {
|
||||||
|
DartSassBinaryName = dartSassBinaryNameV1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
dartSassBinaryNameV1 = "dart-sass-embedded"
|
||||||
|
dartSassBinaryNamesV2 = []string{"dart-sass", "sass"}
|
||||||
|
)
|
||||||
|
|
||||||
|
func IsDartSassV2() bool {
|
||||||
|
return !strings.Contains(DartSassBinaryName, "embedded")
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ const securityConfigKey = "security"
|
||||||
var DefaultConfig = Config{
|
var DefaultConfig = Config{
|
||||||
Exec: Exec{
|
Exec: Exec{
|
||||||
Allow: NewWhitelist(
|
Allow: NewWhitelist(
|
||||||
"^dart-sass-embedded$",
|
"^(dart-)?sass(-embedded)?$", // sass, dart-sass, dart-sass-embedded.
|
||||||
"^go$", // for Go Modules
|
"^go$", // for Go Modules
|
||||||
"^npx$", // used by all Node tools (Babel, PostCSS).
|
"^npx$", // used by all Node tools (Babel, PostCSS).
|
||||||
"^postcss$",
|
"^postcss$",
|
||||||
|
|
|
@ -140,7 +140,7 @@ func TestToTOML(t *testing.T) {
|
||||||
got := DefaultConfig.ToTOML()
|
got := DefaultConfig.ToTOML()
|
||||||
|
|
||||||
c.Assert(got, qt.Equals,
|
c.Assert(got, qt.Equals,
|
||||||
"[security]\n enableInlineShortcodes = false\n\n [security.exec]\n allow = ['^dart-sass-embedded$', '^go$', '^npx$', '^postcss$']\n osEnv = ['(?i)^((HTTPS?|NO)_PROXY|PATH(EXT)?|APPDATA|TE?MP|TERM|GO\\w+)$']\n\n [security.funcs]\n getenv = ['^HUGO_', '^CI$']\n\n [security.http]\n methods = ['(?i)GET|POST']\n urls = ['.*']",
|
"[security]\n enableInlineShortcodes = false\n\n [security.exec]\n allow = ['^(dart-)?sass(-embedded)?$', '^go$', '^npx$', '^postcss$']\n osEnv = ['(?i)^((HTTPS?|NO)_PROXY|PATH(EXT)?|APPDATA|TE?MP|TERM|GO\\w+)$']\n\n [security.funcs]\n getenv = ['^HUGO_', '^CI$']\n\n [security.http]\n methods = ['(?i)GET|POST']\n urls = ['.*']",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
go.mod
3
go.mod
|
@ -10,7 +10,8 @@ require (
|
||||||
github.com/bep/debounce v1.2.0
|
github.com/bep/debounce v1.2.0
|
||||||
github.com/bep/gitmap v1.1.2
|
github.com/bep/gitmap v1.1.2
|
||||||
github.com/bep/goat v0.5.0
|
github.com/bep/goat v0.5.0
|
||||||
github.com/bep/godartsass v1.1.0
|
github.com/bep/godartsass v1.2.0
|
||||||
|
github.com/bep/godartsass/v2 v2.0.0
|
||||||
github.com/bep/golibsass v1.1.1
|
github.com/bep/golibsass v1.1.1
|
||||||
github.com/bep/gowebp v0.2.0
|
github.com/bep/gowebp v0.2.0
|
||||||
github.com/bep/helpers v0.4.0
|
github.com/bep/helpers v0.4.0
|
||||||
|
|
10
go.sum
10
go.sum
|
@ -168,12 +168,10 @@ github.com/bep/gitmap v1.1.2 h1:zk04w1qc1COTZPPYWDQHvns3y1afOsdRfraFQ3qI840=
|
||||||
github.com/bep/gitmap v1.1.2/go.mod h1:g9VRETxFUXNWzMiuxOwcudo6DfZkW9jOsOW0Ft4kYaY=
|
github.com/bep/gitmap v1.1.2/go.mod h1:g9VRETxFUXNWzMiuxOwcudo6DfZkW9jOsOW0Ft4kYaY=
|
||||||
github.com/bep/goat v0.5.0 h1:S8jLXHCVy/EHIoCY+btKkmcxcXFd34a0Q63/0D4TKeA=
|
github.com/bep/goat v0.5.0 h1:S8jLXHCVy/EHIoCY+btKkmcxcXFd34a0Q63/0D4TKeA=
|
||||||
github.com/bep/goat v0.5.0/go.mod h1:Md9x7gRxiWKs85yHlVTvHQw9rg86Bm+Y4SuYE8CTH7c=
|
github.com/bep/goat v0.5.0/go.mod h1:Md9x7gRxiWKs85yHlVTvHQw9rg86Bm+Y4SuYE8CTH7c=
|
||||||
github.com/bep/godartsass v0.16.0 h1:nTpenrZBQjVSjLkCw3AgnYmBB2czauTJa4BLLv448qg=
|
github.com/bep/godartsass v1.2.0 h1:E2VvQrxAHAFwbjyOIExAMmogTItSKodoKuijNrGm5yU=
|
||||||
github.com/bep/godartsass v0.16.0/go.mod h1:6LvK9RftsXMxGfsA0LDV12AGc4Jylnu6NgHL+Q5/pE8=
|
github.com/bep/godartsass v1.2.0/go.mod h1:6LvK9RftsXMxGfsA0LDV12AGc4Jylnu6NgHL+Q5/pE8=
|
||||||
github.com/bep/godartsass v1.0.0 h1:vL5TTtPkpEAZowsXydfJ3M1BatR9fH513FP3but9TEM=
|
github.com/bep/godartsass/v2 v2.0.0 h1:Ruht+BpBWkpmW+yAM2dkp7RSSeN0VLaTobyW0CiSP3Y=
|
||||||
github.com/bep/godartsass v1.0.0/go.mod h1:6LvK9RftsXMxGfsA0LDV12AGc4Jylnu6NgHL+Q5/pE8=
|
github.com/bep/godartsass/v2 v2.0.0/go.mod h1:AcP8QgC+OwOXEq6im0WgDRYK7scDsmZCEW62o1prQLo=
|
||||||
github.com/bep/godartsass v1.1.0 h1:MYNXVQMFoohxue9sCbHi+bWp4AeykvH40gQj1fd9q1c=
|
|
||||||
github.com/bep/godartsass v1.1.0/go.mod h1:6LvK9RftsXMxGfsA0LDV12AGc4Jylnu6NgHL+Q5/pE8=
|
|
||||||
github.com/bep/golibsass v1.1.1 h1:xkaet75ygImMYjM+FnHIT3xJn7H0xBA9UxSOJjk8Khw=
|
github.com/bep/golibsass v1.1.1 h1:xkaet75ygImMYjM+FnHIT3xJn7H0xBA9UxSOJjk8Khw=
|
||||||
github.com/bep/golibsass v1.1.1/go.mod h1:DL87K8Un/+pWUS75ggYv41bliGiolxzDKWJAq3eJ1MA=
|
github.com/bep/golibsass v1.1.1/go.mod h1:DL87K8Un/+pWUS75ggYv41bliGiolxzDKWJAq3eJ1MA=
|
||||||
github.com/bep/gowebp v0.2.0 h1:ZVfK8i9PpZqKHEmthQSt3qCnnHycbLzBPEsVtk2ch2Q=
|
github.com/bep/gowebp v0.2.0 h1:ZVfK8i9PpZqKHEmthQSt3qCnnHycbLzBPEsVtk2ch2Q=
|
||||||
|
|
|
@ -42,7 +42,6 @@ func TestSecurityPolicies(t *testing.T) {
|
||||||
} else {
|
} else {
|
||||||
b.Build(BuildCfg{})
|
b.Build(BuildCfg{})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
httpTestVariant := func(c *qt.C, templ, expectErr string, withBuilder func(b *sitesBuilder)) {
|
httpTestVariant := func(c *qt.C, templ, expectErr string, withBuilder func(b *sitesBuilder)) {
|
||||||
|
@ -145,7 +144,7 @@ allow="none"
|
||||||
`)
|
`)
|
||||||
b.WithTemplatesAdded("index.html", `{{ $scss := "body { color: #333; }" | resources.FromString "foo.scss" | resources.ToCSS (dict "transpiler" "dartsass") }}`)
|
b.WithTemplatesAdded("index.html", `{{ $scss := "body { color: #333; }" | resources.FromString "foo.scss" | resources.ToCSS (dict "transpiler" "dartsass") }}`)
|
||||||
}
|
}
|
||||||
testVariant(c, cb, `(?s).*"dart-sass-embedded" is not whitelisted in policy "security\.exec\.allow".*`)
|
testVariant(c, cb, `(?s).*sass(-embedded)?" is not whitelisted in policy "security\.exec\.allow".*`)
|
||||||
})
|
})
|
||||||
|
|
||||||
c.Run("resources.GetRemote, OK", func(c *qt.C) {
|
c.Run("resources.GetRemote, OK", func(c *qt.C) {
|
||||||
|
|
|
@ -20,7 +20,10 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
godartsassv1 "github.com/bep/godartsass"
|
||||||
|
"github.com/bep/godartsass/v2"
|
||||||
"github.com/gohugoio/hugo/common/herrors"
|
"github.com/gohugoio/hugo/common/herrors"
|
||||||
|
"github.com/gohugoio/hugo/common/hugo"
|
||||||
"github.com/gohugoio/hugo/helpers"
|
"github.com/gohugoio/hugo/helpers"
|
||||||
"github.com/gohugoio/hugo/hugofs"
|
"github.com/gohugoio/hugo/hugofs"
|
||||||
"github.com/gohugoio/hugo/hugolib/filesystems"
|
"github.com/gohugoio/hugo/hugolib/filesystems"
|
||||||
|
@ -28,7 +31,6 @@ import (
|
||||||
"github.com/gohugoio/hugo/resources/resource"
|
"github.com/gohugoio/hugo/resources/resource"
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
|
|
||||||
"github.com/bep/godartsass"
|
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -44,11 +46,23 @@ func New(fs *filesystems.SourceFilesystem, rs *resources.Spec) (*Client, error)
|
||||||
return &Client{dartSassNotAvailable: true}, nil
|
return &Client{dartSassNotAvailable: true}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := rs.ExecHelper.Sec().CheckAllowedExec(dartSassEmbeddedBinaryName); err != nil {
|
if hugo.DartSassBinaryName == "" {
|
||||||
|
return nil, fmt.Errorf("no Dart Sass binary found in $PATH")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := rs.ExecHelper.Sec().CheckAllowedExec(hugo.DartSassBinaryName); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
transpiler, err := godartsass.Start(godartsass.Options{
|
var (
|
||||||
|
transpiler *godartsass.Transpiler
|
||||||
|
transpilerv1 *godartsassv1.Transpiler
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
if hugo.IsDartSassV2() {
|
||||||
|
transpiler, err = godartsass.Start(godartsass.Options{
|
||||||
|
DartSassEmbeddedFilename: hugo.DartSassBinaryName,
|
||||||
LogEventHandler: func(event godartsass.LogEvent) {
|
LogEventHandler: func(event godartsass.LogEvent) {
|
||||||
message := strings.ReplaceAll(event.Message, dartSassStdinPrefix, "")
|
message := strings.ReplaceAll(event.Message, dartSassStdinPrefix, "")
|
||||||
switch event.Type {
|
switch event.Type {
|
||||||
|
@ -61,10 +75,28 @@ func New(fs *filesystems.SourceFilesystem, rs *resources.Spec) (*Client, error)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
} else {
|
||||||
|
transpilerv1, err = godartsassv1.Start(godartsassv1.Options{
|
||||||
|
DartSassEmbeddedFilename: hugo.DartSassBinaryName,
|
||||||
|
LogEventHandler: func(event godartsassv1.LogEvent) {
|
||||||
|
message := strings.ReplaceAll(event.Message, dartSassStdinPrefix, "")
|
||||||
|
switch event.Type {
|
||||||
|
case godartsassv1.LogEventTypeDebug:
|
||||||
|
// Log as Info for now, we may adjust this if it gets too chatty.
|
||||||
|
rs.Logger.Infof("Dart Sass: %s", message)
|
||||||
|
default:
|
||||||
|
// The rest are either deprecations or @warn statements.
|
||||||
|
rs.Logger.Warnf("Dart Sass: %s", message)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &Client{sfs: fs, workFs: rs.BaseFs.Work, rs: rs, transpiler: transpiler}, nil
|
return &Client{sfs: fs, workFs: rs.BaseFs.Work, rs: rs, transpiler: transpiler, transpilerV1: transpilerv1}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
|
@ -72,7 +104,10 @@ type Client struct {
|
||||||
rs *resources.Spec
|
rs *resources.Spec
|
||||||
sfs *filesystems.SourceFilesystem
|
sfs *filesystems.SourceFilesystem
|
||||||
workFs afero.Fs
|
workFs afero.Fs
|
||||||
|
|
||||||
|
// One of these are non-nil.
|
||||||
transpiler *godartsass.Transpiler
|
transpiler *godartsass.Transpiler
|
||||||
|
transpilerV1 *godartsassv1.Transpiler
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) ToCSS(res resources.ResourceTransformer, args map[string]any) (resource.Resource, error) {
|
func (c *Client) ToCSS(res resources.ResourceTransformer, args map[string]any) (resource.Resource, error) {
|
||||||
|
@ -83,23 +118,44 @@ func (c *Client) ToCSS(res resources.ResourceTransformer, args map[string]any) (
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Close() error {
|
func (c *Client) Close() error {
|
||||||
if c.transpiler == nil {
|
if c.transpilerV1 != nil {
|
||||||
return nil
|
return c.transpilerV1.Close()
|
||||||
}
|
}
|
||||||
|
if c.transpiler != nil {
|
||||||
return c.transpiler.Close()
|
return c.transpiler.Close()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) toCSS(args godartsass.Args, src io.Reader) (godartsass.Result, error) {
|
func (c *Client) toCSS(args godartsass.Args, src io.Reader) (godartsass.Result, error) {
|
||||||
var res godartsass.Result
|
|
||||||
|
|
||||||
in := helpers.ReaderToString(src)
|
in := helpers.ReaderToString(src)
|
||||||
|
|
||||||
args.Source = in
|
args.Source = in
|
||||||
|
|
||||||
res, err := c.transpiler.Execute(args)
|
var (
|
||||||
|
err error
|
||||||
|
res godartsass.Result
|
||||||
|
)
|
||||||
|
|
||||||
|
if c.transpilerV1 != nil {
|
||||||
|
var resv1 godartsassv1.Result
|
||||||
|
var argsv1 godartsassv1.Args
|
||||||
|
mapstructure.Decode(args, &argsv1)
|
||||||
|
if args.ImportResolver != nil {
|
||||||
|
argsv1.ImportResolver = importResolverV1{args.ImportResolver}
|
||||||
|
}
|
||||||
|
resv1, err = c.transpilerV1.Execute(argsv1)
|
||||||
|
if err == nil {
|
||||||
|
mapstructure.Decode(resv1, &res)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
res, err = c.transpiler.Execute(args)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() == "unexpected EOF" {
|
if err.Error() == "unexpected EOF" {
|
||||||
return res, fmt.Errorf("got unexpected EOF when executing %q. The user running hugo must have read and execute permissions on this program. With execute permissions only, this error is thrown.", dartSassEmbeddedBinaryName)
|
return res, fmt.Errorf("got unexpected EOF when executing %q. The user running hugo must have read and execute permissions on this program. With execute permissions only, this error is thrown.", hugo.DartSassBinaryName)
|
||||||
}
|
}
|
||||||
return res, herrors.NewFileErrorFromFileInErr(err, hugofs.Os, herrors.OffsetMatcher)
|
return res, herrors.NewFileErrorFromFileInErr(err, hugofs.Os, herrors.OffsetMatcher)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/common/hexec"
|
"github.com/gohugoio/hugo/common/hugo"
|
||||||
"github.com/gohugoio/hugo/common/paths"
|
"github.com/gohugoio/hugo/common/paths"
|
||||||
"github.com/gohugoio/hugo/htesting"
|
"github.com/gohugoio/hugo/htesting"
|
||||||
"github.com/gohugoio/hugo/media"
|
"github.com/gohugoio/hugo/media"
|
||||||
|
@ -34,11 +34,8 @@ import (
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/hugofs"
|
"github.com/gohugoio/hugo/hugofs"
|
||||||
|
|
||||||
"github.com/bep/godartsass"
|
godartsassv1 "github.com/bep/godartsass"
|
||||||
)
|
"github.com/bep/godartsass/v2"
|
||||||
|
|
||||||
const (
|
|
||||||
dartSassEmbeddedBinaryName = "dart-sass-embedded"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Supports returns whether dart-sass-embedded is found in $PATH.
|
// Supports returns whether dart-sass-embedded is found in $PATH.
|
||||||
|
@ -46,7 +43,7 @@ func Supports() bool {
|
||||||
if htesting.SupportsAll() {
|
if htesting.SupportsAll() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return hexec.InPath(dartSassEmbeddedBinaryName)
|
return hugo.DartSassBinaryName != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
type transform struct {
|
type transform struct {
|
||||||
|
@ -201,3 +198,12 @@ func (t importResolver) Load(url string) (godartsass.Import, error) {
|
||||||
return godartsass.Import{Content: string(b), SourceSyntax: sourceSyntax}, err
|
return godartsass.Import{Content: string(b), SourceSyntax: sourceSyntax}, err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type importResolverV1 struct {
|
||||||
|
godartsass.ImportResolver
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t importResolverV1) Load(url string) (godartsassv1.Import, error) {
|
||||||
|
res, err := t.ImportResolver.Load(url)
|
||||||
|
return godartsassv1.Import{Content: res.Content, SourceSyntax: godartsassv1.SourceSyntax(res.SourceSyntax)}, err
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue