From 95d94743309a6864a12de1a6d9949c8d342b3faa Mon Sep 17 00:00:00 2001 From: Joseph Kato Date: Wed, 20 Nov 2024 15:39:38 -0800 Subject: [PATCH] WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP --- .github/workflows/main.yml | 20 ++++++---- .gitignore | 3 +- Hugo/.vale.ini | 10 ----- MDX/.vale.ini | 21 ++++++++++ Makefile | 6 +-- README.md | 6 ++- go.mod | 9 +---- go.sum | 6 --- main.go | 28 +++++++++++-- main_test.go | 46 ---------------------- testdata/.vale.ini | 4 +- testdata/in.md | 56 ++++++++++++++++++++++++++ testdata/shortcodes.md | 81 -------------------------------------- testdata/test.ct | 22 ----------- testdata/test.mdx | 47 ++++++++++++++++++++++ 15 files changed, 172 insertions(+), 193 deletions(-) delete mode 100644 Hugo/.vale.ini create mode 100644 MDX/.vale.ini delete mode 100644 go.sum delete mode 100644 main_test.go create mode 100644 testdata/in.md delete mode 100644 testdata/shortcodes.md delete mode 100644 testdata/test.ct create mode 100644 testdata/test.mdx diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 012df14..657bf5b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,14 +11,14 @@ jobs: with: fetch-depth: 0 - - run: zip -r Hugo.zip Hugo -x "*.DS_Store" + - run: zip -r MDX.zip MDX -x "*.DS_Store" - name: Upload style to release uses: svenstaro/upload-release-action@v2 if: startsWith(github.ref, 'refs/tags/') with: repo_token: ${{ secrets.GITHUB_TOKEN }} - file: Hugo.zip + file: MDX.zip test: runs-on: ubuntu-latest @@ -34,13 +34,17 @@ jobs: - name: Install Deps run: | wget https://github.com/errata-ai/vale/releases/download/v${VALE_VERSION}/vale_${VALE_VERSION}_Linux_64-bit.tar.gz - mkdir bin && tar -xvzf vale_${VALE_VERSION}_Linux_64-bit.tar.gz -C bin - echo "./bin" >> $GITHUB_PATH + mkdir testdata/bin && tar -xvzf vale_${VALE_VERSION}_Linux_64-bit.tar.gz -C testdata/bin + echo "./testdata/bin" >> $GITHUB_PATH + ./testdata/bin/vale -v env: - VALE_VERSION: 3.3.0 + VALE_VERSION: 3.9.1 - name: Features run: | - zip -r Hugo.zip Hugo -x "*.DS_Store" - cd testdata && ../bin/vale sync && cd - - go test -v ./... + zip -r MDX.zip MDX -x "*.DS_Store" + cd testdata + ./bin/vale sync + ./bin/vale transform test.mdx > out.md + cd - + go run main.go diff --git a/.gitignore b/.gitignore index 6c5b1a1..d84379d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ -Hugo.zip +MDX.zip /testdata/styles +/testdata/out.md # Binaries for programs and plugins *.exe diff --git a/Hugo/.vale.ini b/Hugo/.vale.ini deleted file mode 100644 index 4347ca9..0000000 --- a/Hugo/.vale.ini +++ /dev/null @@ -1,10 +0,0 @@ -[*.md] -# Exclude `{{< ... >}}`, `{{% ... %}}`, [Who]({{< ... >}}) -TokenIgnores = ({{[%<] .* [%>]}}.*?{{[%<] ?/.* [%>]}}), \ -(\[.+\]\({{< .+ >}}\)), \ -[^\S\r\n]({{[%<] \w+ .+ [%>]}})\s, \ -[^\S\r\n]({{[%<](?:/\*) .* (?:\*/)[%>]}})\s - -# Exclude `{{< myshortcode `This is some HTML, ... >}}` -BlockIgnores = (?sm)^({{[%<] \w+ [^{]*?\s[%>]}})\n$, \ -(?s) *({{< highlight [^>]* ?>}}.*?{{< ?/ ?highlight >}}) diff --git a/MDX/.vale.ini b/MDX/.vale.ini new file mode 100644 index 0000000..d1f1a54 --- /dev/null +++ b/MDX/.vale.ini @@ -0,0 +1,21 @@ +[formats] +mdx = md + +[*.mdx] +CommentDelimiters = {/*, */} + +# Exclude: +# +# `import ...`, `export ...` +# `` +# `...` +# `{ ... }` +TokenIgnores = (?sm)((?:import|export) .+?$), \ +(?)(?!`), \ +(<[A-Z]\w+>.+?<\/[A-Z]\w+>) + +# Exclude: +# +# `` +BlockIgnores = (?sm)^(<\w+\n .*\s\/>)$, \ +(?sm)^({.+.*}) diff --git a/Makefile b/Makefile index cd33e18..709bfe7 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,10 @@ all: test zip: - zip -r Hugo.zip Hugo -x "*.DS_Store" + zip -r MDX.zip MDX -x "*.DS_Store" sync: - cd testdata && vale sync && cd - + cd testdata && vale sync && vale transform test.mdx > out.md && cd - test: zip sync - go test -v ./... + go run main.go diff --git a/README.md b/README.md index 93d6a18..15d9c90 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ -# Hugo +# MDX -A Vale configuration for Hugo-generated static sites. +A Vale configuration for sites using [MDX][1]. ## Testing ``` $ make test ``` + +[1]: https://mdxjs.com diff --git a/go.mod b/go.mod index ade82c3..8c294fa 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,3 @@ -module github.com/errata-ai/Hugo +module github.com/errata-ai/MDX go 1.17 - -require github.com/google/go-cmdtest v0.4.0 - -require ( - github.com/google/go-cmp v0.3.1 // indirect - github.com/google/renameio v0.1.0 // indirect -) diff --git a/go.sum b/go.sum deleted file mode 100644 index 57cabf1..0000000 --- a/go.sum +++ /dev/null @@ -1,6 +0,0 @@ -github.com/google/go-cmdtest v0.4.0 h1:ToXh6W5spLp3npJV92tk6d5hIpUPYEzHLkD+rncbyhI= -github.com/google/go-cmdtest v0.4.0/go.mod h1:apVn/GCasLZUVpAJ6oWAuyP7Ne7CEsQbTnc0plM3m+o= -github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/renameio v0.1.0 h1:GOZbcHa3HfsPKPlmyPyN2KEohoMXOhdMbHrvbpl2QaA= -github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= diff --git a/main.go b/main.go index 2ce8d07..d2d6887 100644 --- a/main.go +++ b/main.go @@ -1,8 +1,28 @@ package main -import "os" +import ( + "errors" + "os" + "path/filepath" +) -func cdf() int { - os.Chdir(os.Args[1]) - return 0 +func main() { + expected := filepath.Join("testdata", "in.md") + observed := filepath.Join("testdata", "out.md") + + // Read the expected and observed files + expectedContent, err := os.ReadFile(expected) + if err != nil { + panic(err) + } + + observedContent, err := os.ReadFile(observed) + if err != nil { + panic(err) + } + + // Compare the contents of the files + if string(expectedContent) != string(observedContent) { + panic(errors.New("expected and observed files do not match")) + } } diff --git a/main_test.go b/main_test.go deleted file mode 100644 index 3b04cbb..0000000 --- a/main_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "os" - "os/exec" - "path/filepath" - "runtime" - "testing" - - "github.com/google/go-cmdtest" -) - -var update = flag.Bool("update", false, "replace test file contents with output") - -func Test(t *testing.T) { - ts, err := cmdtest.Read("testdata") - if err != nil { - t.Fatal(err) - } - - ts.Setup = func(_ string) error { - _, testFileName, _, ok := runtime.Caller(0) - if !ok { - return fmt.Errorf("failed get real working directory from caller") - } - - projectRootDir := filepath.Join(filepath.Dir(testFileName), "testdata") - if err := os.Setenv("ROOTDIR", projectRootDir); err != nil { - return fmt.Errorf("failed change 'ROOTDIR' to caller working directory: %v", err) - } - - return nil - } - - path, err := exec.LookPath("vale") - if err != nil { - path = "./bin/vale" - } - - ts.Commands["vale"] = cmdtest.Program(path) - ts.Commands["cdf"] = cmdtest.InProcessProgram("cdf", cdf) - - ts.Run(t, *update) -} diff --git a/testdata/.vale.ini b/testdata/.vale.ini index 6d6ebd5..6dd3cf0 100644 --- a/testdata/.vale.ini +++ b/testdata/.vale.ini @@ -1,6 +1,6 @@ StylesPath = styles -Packages = ../Hugo.zip +Packages = ../MDX.zip -[*.md] +[*.mdx] BasedOnStyles = Vale diff --git a/testdata/in.md b/testdata/in.md new file mode 100644 index 0000000..effd447 --- /dev/null +++ b/testdata/in.md @@ -0,0 +1,56 @@ +# Hello, world! + +`import {External} from './some/place.js'` +`import {Chart} from './chart.js'` +`import population from './population.js'` + +`export const pi = 3.14` +`export const Local = properties => ` + +`` + +An `external` component and a `local one`. + +
+ > Some notable things in a block quote! +
+ +`` +`` + +`` + +You can also use objects with components, such as the `thisOne` component on +the `myComponents` object: `` + + +``` +`} +/> +``` + + +Two 🍰 is: {Math.PI * 2} + + +``` +{(function () { + const guess = Math.random() + + if (guess > 0.66) { + return Look at us. + } + + if (guess > 0.33) { + return Who would have guessed?! + } + + return Not me. +})()} +``` + + diff --git a/testdata/shortcodes.md b/testdata/shortcodes.md deleted file mode 100644 index 0f51715..0000000 --- a/testdata/shortcodes.md +++ /dev/null @@ -1,81 +0,0 @@ -# Shortcodes - -> Shortcodes are simple snippets inside your content files calling built-in or -> custom templates. - -{{% mdshortcode %}}Stuff to `process` in the *center*.{{% /mdshortcode %}} - -Shortcodes are non-standard markup that appears within normal Markdown. - -{{< highlt go >}} A bunch of code here {{< /highlt >}} - -Shortcodes are non-standard markup that appears within normal Markdown. - -{{< myshortcode This is some HTML, -and a new line with a "quoted string". >}} - -Shortcodes are non-standard markup that appears within normal Markdown. - -{{< myshortcode This is some HTML,. >}} - -Shortcodes are non-standard markup that appears within normal Markdown. - -{{< myshortcode src="/media/spf13.jpg" title="Steve Francia" >}} - -Shortcodes are non-standard markup that appears within normal Markdown. - -{{< highlight html >}} -
-
-

{{ .Title }}

- {{ range .Pages }} - {{ .Render "summary"}} - {{ end }} -
-
-{{< /highlight >}} - -Shortcodes are non-standard markup that appears within normal Markdown. - -{{< instagram BWNjjyYFxVx hidecaption >}} - -Shortcodes are non-standard markup that appears within normal Markdown. - -[Who]({{< relref "about.md#who" >}}) - -hidecaption - -{{< youtube id="w7Ft2ymGmfc" autoplay="true" >}} - -Shortcodes are non-standard markup that appears within normal Markdown. - -[Contact us]({{< relref "contact/index.md" >}}) if you have any questions. - -Shortcodes are non-standard markup that appears within normal Markdown. - -- {{< myshortcode src="/media/spf13.jpg" title="Steve Francia" >}} - -Shortcodes are non-standard markup that appears within normal Markdown. - -Shortcodes can be used {{< myshortcode src="/media/spf13.jpg" title="Steve Francia" >}} inside a paragraph. - -Shortcodes are non-standard markup that appears within normal Markdown. - -To escape shortcodes, use the Hugo comment syntax. -For example: - -- {{}} -- {{}} -- {{%/* commentedoutshortcodemd */%}} -- {{%/* /closecommentedoutshortcodemd */%}} - -The unspalsh shortcode: - -{{% unsplash name="xxx" href="xxx" %}} - -Another unspalsh shortcode: - -{{% unsplash - name="xxx" - href="xxx" -%}} diff --git a/testdata/test.ct b/testdata/test.ct deleted file mode 100644 index 6cd3d7e..0000000 --- a/testdata/test.ct +++ /dev/null @@ -1,22 +0,0 @@ -$ cdf ${ROOTDIR} -$ vale --output=line --sort --normalize --relative --no-exit --no-global shortcodes.md -shortcodes.md:1:3:Vale.Spelling:Did you really mean 'Shortcodes'? -shortcodes.md:3:3:Vale.Spelling:Did you really mean 'Shortcodes'? -shortcodes.md:8:1:Vale.Spelling:Did you really mean 'Shortcodes'? -shortcodes.md:12:1:Vale.Spelling:Did you really mean 'Shortcodes'? -shortcodes.md:17:1:Vale.Spelling:Did you really mean 'Shortcodes'? -shortcodes.md:21:1:Vale.Spelling:Did you really mean 'Shortcodes'? -shortcodes.md:25:1:Vale.Spelling:Did you really mean 'Shortcodes'? -shortcodes.md:38:1:Vale.Spelling:Did you really mean 'Shortcodes'? -shortcodes.md:42:1:Vale.Spelling:Did you really mean 'Shortcodes'? -shortcodes.md:46:1:Vale.Spelling:Did you really mean 'hidecaption'? -shortcodes.md:50:1:Vale.Spelling:Did you really mean 'Shortcodes'? -shortcodes.md:54:1:Vale.Spelling:Did you really mean 'Shortcodes'? -shortcodes.md:58:1:Vale.Spelling:Did you really mean 'Shortcodes'? -shortcodes.md:60:1:Vale.Spelling:Did you really mean 'Shortcodes'? -shortcodes.md:62:1:Vale.Spelling:Did you really mean 'Shortcodes'? -shortcodes.md:64:11:Vale.Spelling:Did you really mean 'shortcodes'? -shortcodes.md:72:5:Vale.Spelling:Did you really mean 'unspalsh'? -shortcodes.md:72:14:Vale.Spelling:Did you really mean 'shortcode'? -shortcodes.md:76:9:Vale.Spelling:Did you really mean 'unspalsh'? -shortcodes.md:76:18:Vale.Spelling:Did you really mean 'shortcode'? diff --git a/testdata/test.mdx b/testdata/test.mdx new file mode 100644 index 0000000..10518ea --- /dev/null +++ b/testdata/test.mdx @@ -0,0 +1,47 @@ +# Hello, world! + +import {External} from './some/place.js' +import {Chart} from './chart.js' +import population from './population.js' + +export const pi = 3.14 +export const Local = properties => + + + +An external component and a local one. + +
+ > Some notable things in a block quote! +
+ + + + + + +You can also use objects with components, such as the `thisOne` component on +the `myComponents` object: + +} +/> + +Two 🍰 is: {Math.PI * 2} + +{(function () { + const guess = Math.random() + + if (guess > 0.66) { + return Look at us. + } + + if (guess > 0.33) { + return Who would have guessed?! + } + + return Not me. +})()}