Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ jobs:
echo "$env:GITHUB_WORKSPACE\dart-sass" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
shell: pwsh

- name: Set timezone
run: tzutil /s "Eastern Standard Time"

- name: Build
run: go build main.go

- name: Test
run: go test ./...
continue-on-error: true # Allow failures until Windows-specific bugs are fixed
3 changes: 2 additions & 1 deletion collection/collection_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package collection

import (
"path/filepath"
"testing"

"github.com/osteele/gojekyll/config"
Expand All @@ -20,7 +21,7 @@ func TestNewCollection(t *testing.T) {

c1 := New(site, "c", map[string]interface{}{"output": true})
require.Equal(t, true, c1.Output())
require.Equal(t, "_c/", c1.PathPrefix())
require.Equal(t, "_c/", filepath.ToSlash(c1.PathPrefix()))

c2 := New(site, "c", map[string]interface{}{})
require.Equal(t, false, c2.Output())
Expand Down
3 changes: 2 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"path/filepath"
"strings"
"testing"

Expand All @@ -9,7 +10,7 @@ import (

func TestConfig_SourceDir(t *testing.T) {
c := Default()
require.True(t, strings.HasPrefix(c.SourceDir(), "/"))
require.True(t, filepath.IsAbs(c.SourceDir()) || strings.HasPrefix(c.SourceDir(), "/"))
}
func TestDefaultConfig(t *testing.T) {
c := Default()
Expand Down
2 changes: 1 addition & 1 deletion pages/page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestPage_Write(t *testing.T) {
require.Contains(t, err.Error(), "render error")
pe, ok := err.(utils.PathError)
require.True(t, ok)
require.Equal(t, "testdata/liquid_error.md", pe.Path())
require.Equal(t, "testdata/liquid_error.md", filepath.ToSlash(pe.Path()))
})

t.Run("layout: none", func(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions site/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ func (s *Site) KeepFile(filename string) bool {

// FilePathPage returns a Page, give a file path relative to site source directory.
func (s *Site) FilePathPage(rel string) (Document, bool) {
// Normalize the input path to use OS-specific separators
// This handles cases where templates use forward slashes (e.g., {% link _c1/c1p1.md %})
rel = filepath.FromSlash(rel)

// This looks wasteful. If it shows up as a hotspot, you know what to do.
for _, p := range s.Routes {
if p.Source() != "" {
Expand Down
16 changes: 6 additions & 10 deletions utils/filepath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,27 @@ package utils

import (
"os"
"path/filepath"
"strings"
"testing"
"time"

"github.com/stretchr/testify/require"
)

func timeMustParse(s string) time.Time {
t, err := time.Parse(time.RFC3339, s)
if err != nil {
panic(err)
}
return t
}

func TestMustAbs(t *testing.T) {
require.True(t, strings.HasPrefix(MustAbs("."), "/"))
abs := MustAbs(".")
require.True(t, filepath.IsAbs(abs) || strings.HasPrefix(abs, "/"))
}

func TestParseFilenameDate(t *testing.T) {
os.Setenv("TZ", "America/New_York") // nolint: errcheck
d, title, found := ParseFilenameDateTitle("2017-07-02-post.html")
require.True(t, found)
require.Equal(t, "Post", title)
require.Equal(t, timeMustParse("2017-07-02T00:00:00-04:00"), d)
// The date should be 2017-07-02 at midnight in the local timezone
expected := time.Date(2017, 7, 2, 0, 0, 0, 0, time.Local)
require.Equal(t, expected, d)

_, _, found = ParseFilenameDateTitle("not-post.html")
require.False(t, found)
Expand Down
9 changes: 7 additions & 2 deletions utils/ioutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ func PostfixWalk(root string, walkFn filepath.WalkFunc) error {

// IsNotEmpty returns a boolean indicating whether the error is known to report that a directory is not empty.
func IsNotEmpty(err error) bool {
if err, ok := err.(*os.PathError); ok {
return err.Err.(syscall.Errno) == syscall.ENOTEMPTY
if pathErr, ok := err.(*os.PathError); ok {
if errno, ok := pathErr.Err.(syscall.Errno); ok {
// Check for platform-specific "directory not empty" errors
// Unix/Linux/macOS: ENOTEMPTY
// Windows: ERROR_DIR_NOT_EMPTY (checked via platform-specific helper)
return errno == syscall.ENOTEMPTY || isWindowsDirNotEmpty(errno)
}
}
return false
}
Expand Down
5 changes: 4 additions & 1 deletion utils/ioutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ func TestCopyFileContents(t *testing.T) {
if err != nil {
t.Fatal(err)
}
require.Equal(t, "content\n", string(b))
// Normalize line endings for cross-platform compatibility
content := string(b)
// Accept either Unix or Windows line endings
require.True(t, content == "content\n" || content == "content\r\n", "expected 'content\\n' or 'content\\r\\n', got %q", content)

err = CopyFileContents(f.Name(), testFile("missing.txt"), 0x644)
require.Error(t, err)
Expand Down
10 changes: 10 additions & 0 deletions utils/ioutil_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build !windows

package utils

import "syscall"

// isWindowsDirNotEmpty always returns false on non-Windows platforms
func isWindowsDirNotEmpty(errno syscall.Errno) bool {
return false
}
10 changes: 10 additions & 0 deletions utils/ioutil_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build windows

package utils

import "syscall"

// isWindowsDirNotEmpty checks if the error is Windows ERROR_DIR_NOT_EMPTY
func isWindowsDirNotEmpty(errno syscall.Errno) bool {
return errno == syscall.ERROR_DIR_NOT_EMPTY
}