Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .commitlog.release
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.2.15
v0.2.16-beta.0
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

.PHONY.: all

all: clean build
Expand All @@ -16,7 +15,7 @@ docs: build
./alvu --path="docs" --baseurl="/alvu/" --highlight --hard-wrap=false

docs_dev: build
./alvu --highlight --hard-wrap=false --serve --path='./docs'
DEBUG=true ./alvu --highlight --hard-wrap=false --serve --path='./docs'

pages: docs
rm -rf alvu
Expand Down
159 changes: 159 additions & 0 deletions commands/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package commands

import (
"fmt"
"os"
"path/filepath"

"github.com/barelyhuman/alvu/pkg/alvu"
"github.com/barelyhuman/go/color"
"github.com/urfave/cli/v2"
)

func AlvuInit(c *cli.Context) (err error) {
basePath := c.Args().First()
forceFlag := c.Bool("force")
logger := alvu.NewLogger()
logger.LogPrefix = "[alvu]"

fileInfo, err := os.Stat(basePath)

if err == nil {
if fileInfo.IsDir() && !forceFlag {
logger.Error(fmt.Sprintf("Directory: %v , already exists, cannot overwrite, if you wish to force overwrite use the -f flag with the `init` command", basePath))
os.Exit(1)
}
}

mustCreateDir(basePath, "public")
mustCreateDir(basePath, "hooks")
mustCreateDir(basePath, "pages")
prepareBaseStyles(basePath)
preparePages(basePath)

logger.Success(
fmt.Sprintf("Alvu initialized in: %v", basePath),
)

runStr := color.ColorString{}

fmt.Println(runStr.Dim("\n> Run the following to get started").String())

commandStr := color.ColorString{}
commandStr.Cyan(
fmt.Sprintf("\n alvu -s -path %v\n", basePath),
)
fmt.Println(commandStr.String())
return
}

func mustCreateDir(root, dir string) {
pathToCreate := filepath.Join(root, dir)
err := os.MkdirAll(pathToCreate, os.ModePerm)
if err != nil {
panic(fmt.Sprintf("Failed to create %v due to error: %v\n", pathToCreate, err))
}
}

func prepareBaseStyles(root string) {
fileHandle, err := os.OpenFile(filepath.Join(root, "public", "styles.css"), os.O_CREATE|os.O_RDWR, os.ModePerm)
if err != nil {
fmt.Printf("Failed to open file public/styles.css with error: %v", err)
}
defer fileHandle.Sync()
defer fileHandle.Close()

fileHandle.WriteString(`
/* Resets */
html {
box-sizing: border-box;
font-size: 16px;
font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif;
}

*, *:before, *:after {
box-sizing: inherit;
}

body, h1, h2, h3, h4, h5, h6, p {
margin: 0;
padding: 0;
font-weight: normal;
}

img {
max-width: 100%;
height: auto;
}

/* Styles */

:root {
--base: #efefef;
--text: #181819;
}

@media (prefers-color-scheme: dark) {
:root {
--base: #181819;
--text: #efefef;
}
}

body {

background: var(--base);
color: var(--text);

max-width: 900px;
margin: 0 auto;
padding: 4px;
display: flex;
flex-direction: column;
justify-content: center;
min-height: 100vh;
}


ol,ul,p{
line-height: 1.7;
}

`)

}

func preparePages(root string) {
layoutHandle, _ := os.OpenFile(filepath.Join(root, "pages", "_layout.html"), os.O_CREATE|os.O_RDWR, os.ModePerm)
defer layoutHandle.Sync()
defer layoutHandle.Close()

rootPageHandle, _ := os.OpenFile(filepath.Join(root, "pages", "index.md"), os.O_CREATE|os.O_RDWR, os.ModePerm)

defer rootPageHandle.Sync()
defer rootPageHandle.Close()

layoutHandle.WriteString(`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Alvu | Minimal Starter</title>
<link href="/styles.css" rel="stylesheet">
</head>
<body>
<slot></slot>
</body>
</html>`)

rootPageHandle.WriteString(`# Alvu

- Scriptable
- Fast
- Tiny

In whatever order you'd like...

`)

}
37 changes: 37 additions & 0 deletions commands/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package commands

import (
"os"

"github.com/barelyhuman/alvu/pkg/alvu"
"github.com/joho/godotenv"
"github.com/urfave/cli/v2"
)

func Alvu(c *cli.Context) (err error) {
// Prepare Environment
envFilePath := c.String("env")
if _, err := os.Stat(envFilePath); err == nil {
godotenv.Load(envFilePath)
}

baseConfig := alvu.AlvuConfig{}

// Basics
baseConfig.HookDir = c.String("hooks")
baseConfig.OutDir = c.String("out")
baseConfig.RootPath = c.String("path")

// Transformation Config
baseConfig.BaseURL = c.String("baseurl")
baseConfig.EnableHardWrap = c.Bool("hard-wrap")
baseConfig.EnableHighlighting = c.Bool("highlight")
baseConfig.HighlightingTheme = c.String("highlight-theme")

// Serve config
baseConfig.Serve = c.Bool("serve")
baseConfig.PollDuration = c.Int("poll")
baseConfig.PortNumber = c.String("port")

return baseConfig.Run()
}
19 changes: 9 additions & 10 deletions docs/hooks/00-copy-readme.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ local json = require("json")
ForFile = "00-readme.md"

function Writer(filedata)
local sourcedata = json.decode(filedata)
if sourcedata.name == "00-readme.html"
then
local f = assert(io.open(wdir.."/../readme.md", "rb"))
local content = f:read("*all")
f:close()
sourcedata.content = content
end
return json.encode(sourcedata)
end
local sourcedata = json.decode(filedata)
if sourcedata.name == "00-readme.html" then
local f = assert(io.open(wdir .. "/../readme.md", "rb"))
local content = f:read("*all")
f:close()
sourcedata.content = content
end
return json.encode(sourcedata)
end
67 changes: 34 additions & 33 deletions docs/hooks/01-add-navigation.lua
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
---@diagnostic disable-next-line: undefined-global
local wdir = workingdir

package.path = package.path .. ";" .. wdir .. "/lib/?.lua"

local json = require("json")
local alvu = require("alvu")
local utils = require(wdir .. ".lib.utils")

function Writer(filedata)
local pagesPath = wdir .. "/pages"
local index = {}
local files = alvu.files(pagesPath)

for fileIndex = 1, #files do
local file_name = files[fileIndex]
if not (file_name == "_layout.html" or file_name == "index.md" or utils.starts_with(file_name,"concepts/"))
then
local name = string.gsub(file_name, ".md", "")
name = string.gsub(name, ".html", "")
local title, _ = utils.normalize(name):lower()

table.insert(index, {
name = title,
slug = name
})
end
end

table.insert(index, 1, {
name = "..",
slug = "index"
})

local source_data = json.decode(filedata)

local template = [[
local pagesPath = wdir .. "/pages"
local index = {}
local files = alvu.files(pagesPath)

for fileIndex = 1, #files do
local file_name = files[fileIndex]
if
not (file_name == "_layout.html" or file_name == "index.md" or utils.starts_with(file_name, "concepts/"))
then
local name = string.gsub(file_name, ".md", "")
name = string.gsub(name, ".html", "")
local title, _ = utils.normalize(name):lower()

table.insert(index, {
name = title,
slug = name,
})
end
end

table.insert(index, 1, {
name = "..",
slug = "index",
})

local source_data = json.decode(filedata)

local template = [[
<header class="container">
<nav>
{{$baseurl:=.Meta.BaseURL}}
Expand All @@ -42,13 +44,12 @@ function Writer(filedata)
{{end}}
</nav>
</header>
<main class="container">
]]

source_data.content = template .. "\n" .. source_data.content .. "</main>"
source_data.data = {
index = index
}
source_data.content = template .. "\n" .. source_data.content
source_data.data = {
index = index,
}

return json.encode(source_data)
return json.encode(source_data)
end
2 changes: 1 addition & 1 deletion docs/pages/01-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ can be defined as shown below
<html lang="en">
<head></head>
<body>
{ { .Content } }
<slot></slot>
</body>
</html>
```
Expand Down
4 changes: 3 additions & 1 deletion docs/pages/_layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
</head>

<body>
{{.Content}}
<main class="container">
<slot></slot>
</main>
<footer class="container">
Built with <a href="http://github.com/barelyhuman/alvu">alvu</a>
</footer>
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ rather tight flow made me think this'd work well.
As always, a tiny little tool built for me and hopefully someday someone else
might like it.

Well, let's head to [the basics &rarr;]({{.Meta.BaseURL}}01-basics)
Well, let's head to [the basics &rarr;](/01-basics)
14 changes: 8 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ module github.com/barelyhuman/alvu
go 1.18

require (
github.com/barelyhuman/go v0.2.2-0.20230713173609-2ee88bb52634
github.com/barelyhuman/go v0.2.3-0.20240516192751-30a6c804e4e5
github.com/cjoudrey/gluahttp v0.0.0-20201111170219-25003d9adfa9
github.com/joho/godotenv v1.5.1
github.com/otiai10/copy v1.9.0
github.com/vadv/gopher-lua-libs v0.4.1
github.com/yuin/goldmark v1.5.4
github.com/urfave/cli/v2 v2.27.1
github.com/vadv/gopher-lua-libs v0.5.0
github.com/yuin/goldmark v1.7.1
github.com/yuin/goldmark-highlighting v0.0.0-20220208100518-594be1970594
github.com/yuin/gopher-lua v1.1.0
golang.org/x/net v0.0.0-20200202094626-16171245cfb2
golang.org/x/net v0.17.0
gopkg.in/yaml.v3 v3.0.1
layeh.com/gopher-json v0.0.0-20201124131017-552bb3c4c3bf
)

require (
github.com/alecthomas/chroma v0.10.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
golang.org/x/sys v0.0.0-20220908164124-27713097b956 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)
Loading