From c2bd1636e7829a50bc19dfdb93d2aef3b8503762 Mon Sep 17 00:00:00 2001
From: zztkm <takumi.basket1682@gmail.com>
Date: Wed, 27 Jul 2022 02:17:00 +0900
Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .github/workflows/release.yaml | 83 ++++++++++++++++++++++++++++++++++
 vss.v                          | 48 ++++++++++++--------
 2 files changed, 113 insertions(+), 18 deletions(-)
 create mode 100644 .github/workflows/release.yaml

diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
new file mode 100644
index 0000000..f8d1ee0
--- /dev/null
+++ b/.github/workflows/release.yaml
@@ -0,0 +1,83 @@
+name: release
+
+on:
+  push:
+    tags:
+    - 'v*'
+
+jobs:
+  Release-on-Ubuntu:
+    name: Release on Ubuntu
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v3
+      - uses: denoland/setup-deno@v1
+        with:
+          deno-version: v1.x
+      - uses: goto-bus-stop/setup-zig@v1
+        with:
+          version: 0.9.1
+      - name: make x86_64
+        run: make dist
+      - name: make aarch64
+        run: ./misc/build-aarch64.sh
+      - name: Release
+        uses: softprops/action-gh-release@v1
+        if: startsWith(github.ref, 'refs/tags/')
+        with:
+          files: |
+            dist/**
+
+  Release-on-Darwin:
+    name: Release on Darwin
+    runs-on: macos-latest
+    steps:
+      - uses: actions/checkout@v3
+      - uses: denoland/setup-deno@v1
+        with:
+          deno-version: v1.x
+      - uses: goto-bus-stop/setup-zig@v1
+        with:
+          version: 0.9.1
+      - name: make x86_64
+        run: make dist
+      - name: make aarch64
+        run: ./misc/build-aarch64.sh
+      - name: Release
+        uses: softprops/action-gh-release@v1
+        if: startsWith(github.ref, 'refs/tags/')
+        with:
+          files: |
+            dist/**
+
+  Release-on-Windows:
+    name: Release on Windows
+    runs-on: windows-latest
+    steps:
+      - uses: actions/checkout@v3
+      - uses: denoland/setup-deno@v1
+        with:
+          deno-version: v1.x
+      #- uses: goto-bus-stop/setup-zig@v1
+      #  with:
+      #    version: 0.9.1
+      - uses: msys2/setup-msys2@v2
+        with:
+          update: true
+          install: mingw-w64-x86_64-toolchain
+          msystem: MINGW64
+          path-type: inherit
+      - name: make x86_64
+        shell: msys2 {0}
+        run: |
+          mingw32-make dist
+      #- name: make aarch64
+      #  shell: msys2 {0}
+      #  run: |
+      #    mingw32-make ARCH=aarch64 CC="zig cc -target aarch64-windows"
+      - name: Release
+        uses: softprops/action-gh-release@v1
+        if: startsWith(github.ref, 'refs/tags/')
+        with:
+          files: |
+            dist/**
\ No newline at end of file
diff --git a/vss.v b/vss.v
index 7572e00..beb4c1f 100644
--- a/vss.v
+++ b/vss.v
@@ -4,13 +4,15 @@ import os
 import cli
 import markdown
 
-const markdown_text = "
+const markdown_text = '
 # Open Sea
 
 A static site generator
 
 - [GitHub](https://github.com/zztkm)
-"
+'
+
+const default_dist = 'dist'
 
 fn main() {
 	mut app := cli.Command{
@@ -18,22 +20,7 @@ fn main() {
 		version: '0.0.0'
 		description: 'static site generator'
 		execute: fn (cmd cli.Command) ? {
-			paths := get_paths('testfiles')
-			if paths.len == 0 {
-				println('Cloud not retrieve path')
-				return
-			}
-			for path in paths {
-				println(path)
-			}
-
-			// index_html := $embed_file("layouts/_index.html")
-			title := 'tsurutatakumi.info'
-			contents := markdown.to_html(markdown_text)
-
-			index_html := $tmpl('layouts/_index.html')
-			os.write_file('index.html', index_html) ?
-			return
+			generate_index_page()?
 		}
 	}
 
@@ -45,3 +32,28 @@ fn get_paths(path string) []string {
 	mds := os.walk_ext(path, '.md')
 	return mds
 }
+
+fn generate_index_page() ? {
+	paths := get_paths('testfiles')
+	if paths.len == 0 {
+		println('Cloud not retrieve path')
+		return
+	}
+	for path in paths {
+		println(path)
+	}
+
+	// index_html := $embed_file("layouts/_index.html")
+	title := 'tsurutatakumi.info'
+	contents := markdown.to_html(markdown_text)
+
+	index_html := $tmpl('layouts/_index.html')
+	dist := default_dist
+
+	if !os.exists(dist) {
+		os.mkdir_all(dist, ) // build/_dist/ のようなPATHが渡されても作成できるようにmkdir_allを使う
+	}
+	path := os.join_path(dist, 'index.html')
+	os.write_file(path, index_html)?
+	return
+}