forked from gohugoio/hugo
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See gohugoio#11927
- Loading branch information
Showing
19 changed files
with
15,399 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
go generate ./gen | ||
javy compile js/greet.bundle.js -d -o wasm/greet.wasm | ||
javy compile js/renderkatex.bundle.js -d -o wasm/renderkatex.wasm | ||
touch wasm_test.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//go:generate go run main.go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/evanw/esbuild/pkg/api" | ||
) | ||
|
||
var scripts = []string{ | ||
"greet.js", | ||
"renderkatex.js", | ||
} | ||
|
||
func main() { | ||
for _, script := range scripts { | ||
filename := filepath.Join("../js", script) | ||
err := buildJSBundle(filename) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
} | ||
|
||
func buildJSBundle(filename string) error { | ||
result := api.Build( | ||
api.BuildOptions{ | ||
EntryPoints: []string{filename}, | ||
Bundle: true, | ||
Target: api.ES2020, | ||
Outfile: strings.Replace(filename, ".js", ".bundle.js", 1), | ||
SourceRoot: "../js", | ||
}) | ||
|
||
if len(result.Errors) > 0 { | ||
return fmt.Errorf("build failed: %v", result.Errors) | ||
} | ||
if len(result.OutputFiles) != 1 { | ||
return fmt.Errorf("expected 1 output file, got %d", len(result.OutputFiles)) | ||
} | ||
|
||
of := result.OutputFiles[0] | ||
if err := os.WriteFile(filepath.FromSlash(of.Path), of.Contents, 0o644); err != nil { | ||
return fmt.Errorf("write file failed: %v", err) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Read JSONL from stdin. | ||
export function readInput(handle) { | ||
const buffSize = 1024; | ||
let currentLine = []; | ||
const buffer = new Uint8Array(buffSize); | ||
|
||
// Read all the available bytes | ||
while (true) { | ||
// Stdin file descriptor | ||
const fd = 0; | ||
let bytesRead = 0; | ||
try { | ||
bytesRead = Javy.IO.readSync(fd, buffer); | ||
} catch (e) { | ||
// IO.readSync fails with os error 29 when stdin closes. | ||
if (e.message.includes('os error 29')) { | ||
break; | ||
} | ||
throw new Error('Error reading from stdin'); | ||
} | ||
|
||
if (bytesRead < 0) { | ||
throw new Error('Error reading from stdin'); | ||
break; | ||
} | ||
|
||
if (bytesRead === 0) { | ||
break; | ||
} | ||
|
||
currentLine = [...currentLine, ...buffer.subarray(0, bytesRead)]; | ||
|
||
// Split array into chunks by newline. | ||
let i = 0; | ||
for (let j = 0; i < currentLine.length; i++) { | ||
if (currentLine[i] === 10) { | ||
const chunk = currentLine.splice(j, i + 1); | ||
const arr = new Uint8Array(chunk); | ||
const json = JSON.parse(new TextDecoder().decode(arr)); | ||
handle(json); | ||
j = i + 1; | ||
} | ||
} | ||
// Remove processed data. | ||
currentLine = currentLine.slice(i); | ||
} | ||
} | ||
|
||
// Write JSONL to stdout | ||
export function writeOutput(output) { | ||
const encodedOutput = new TextEncoder().encode(JSON.stringify(output) + '\n'); | ||
const buffer = new Uint8Array(encodedOutput); | ||
// Stdout file descriptor | ||
const fd = 1; | ||
Javy.IO.writeSync(fd, buffer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
(() => { | ||
// ../js/common.js | ||
function readInput(handle) { | ||
const buffSize = 1024; | ||
let currentLine = []; | ||
const buffer = new Uint8Array(buffSize); | ||
while (true) { | ||
const fd = 0; | ||
let bytesRead = 0; | ||
try { | ||
bytesRead = Javy.IO.readSync(fd, buffer); | ||
} catch (e) { | ||
if (e.message.includes("os error 29")) { | ||
break; | ||
} | ||
throw new Error("Error reading from stdin"); | ||
} | ||
if (bytesRead < 0) { | ||
throw new Error("Error reading from stdin"); | ||
break; | ||
} | ||
if (bytesRead === 0) { | ||
break; | ||
} | ||
currentLine = [...currentLine, ...buffer.subarray(0, bytesRead)]; | ||
let i = 0; | ||
for (let j = 0; i < currentLine.length; i++) { | ||
if (currentLine[i] === 10) { | ||
const chunk = currentLine.splice(j, i + 1); | ||
const arr = new Uint8Array(chunk); | ||
const json = JSON.parse(new TextDecoder().decode(arr)); | ||
handle(json); | ||
j = i + 1; | ||
} | ||
} | ||
currentLine = currentLine.slice(i); | ||
} | ||
} | ||
function writeOutput(output) { | ||
const encodedOutput = new TextEncoder().encode(JSON.stringify(output) + "\n"); | ||
const buffer = new Uint8Array(encodedOutput); | ||
const fd = 1; | ||
Javy.IO.writeSync(fd, buffer); | ||
} | ||
|
||
// ../js/greet.js | ||
var greet = function(input) { | ||
writeOutput({ id: input.id, greeting: "Hello " + input.name + "!" }); | ||
}; | ||
readInput(greet); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { readInput, writeOutput } from './common'; | ||
|
||
const greet = function (input) { | ||
writeOutput({ id: input.id, greeting: 'Hello ' + input.name + '!' }); | ||
}; | ||
|
||
readInput(greet); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "js", | ||
"version": "1.0.0", | ||
"main": "greet.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"description": "", | ||
"devDependencies": { | ||
"katex": "^0.16.11" | ||
} | ||
} |
Oops, something went wrong.