You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
979 B
V

2 years ago
module main
import os
import cli
import markdown
2 years ago
const default_index = 'index.md'
2 years ago
const default_dist = 'dist'
2 years ago
fn main() {
mut app := cli.Command{
name: 'vss'
2 years ago
version: '0.0.1'
description: 'static site generator'
2 years ago
execute: fn (cmd cli.Command) ? {
2 years ago
generate_index_page()?
2 years ago
}
}
app.setup()
app.parse(os.args)
2 years ago
}
fn get_paths(path string) []string {
mds := os.walk_ext(path, '.md')
return mds
}
2 years ago
fn generate_index_page() ? {
2 years ago
index_md := os.read_file(default_index)?
// for $tmpl value
2 years ago
title := 'tsurutatakumi.info'
2 years ago
contents := markdown.to_html(index_md)
2 years ago
2 years ago
// tmpl に変数を割り当てるのは今の所無理
// https://github.com/vlang/v/discussions/15068
2 years ago
index_html := $tmpl('layouts/_index.html')
dist := default_dist
if !os.exists(dist) {
2 years ago
os.mkdir_all(dist)? // build/_dist/ のようなPATHが渡されても作成できるようにmkdir_allを使う
2 years ago
}
path := os.join_path(dist, 'index.html')
os.write_file(path, index_html)?
return
}