-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8b1a401
Showing
14 changed files
with
297 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: 2 | ||
|
||
updates: | ||
- package-ecosystem: github-actions | ||
directory: / | ||
schedule: | ||
interval: daily | ||
- package-ecosystem: gomod | ||
directory: / | ||
schedule: | ||
interval: daily |
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,30 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- v* | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: go.mod | ||
|
||
- name: Release | ||
uses: goreleaser/goreleaser-action@v5 | ||
with: | ||
args: release --clean | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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 @@ | ||
/autoindex* | ||
index.html | ||
|
||
dist/ |
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,49 @@ | ||
# This is an example .goreleaser.yml file with some sensible defaults. | ||
# Make sure to check the documentation at https://goreleaser.com | ||
|
||
# The lines below are called `modelines`. See `:help modeline` | ||
# Feel free to remove those if you don't want/need to use them. | ||
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json | ||
# vim: set ts=2 sw=2 tw=0 fo=cnqoj | ||
|
||
version: 1 | ||
|
||
project_name: autoindex | ||
|
||
before: | ||
hooks: | ||
# You may remove this if you don't use go modules. | ||
- go mod tidy | ||
# you may remove this if you don't need go generate | ||
- go generate ./... | ||
|
||
builds: | ||
- main: ./cmd/autoindex | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- windows | ||
- darwin | ||
|
||
archives: | ||
- format: tar.gz | ||
# this name template makes the OS and Arch compatible with the results of `uname`. | ||
name_template: >- | ||
{{ .ProjectName }}_ | ||
{{- title .Os }}_ | ||
{{- if eq .Arch "amd64" }}x86_64 | ||
{{- else if eq .Arch "386" }}i386 | ||
{{- else }}{{ .Arch }}{{ end }} | ||
{{- if .Arm }}v{{ .Arm }}{{ end }} | ||
# use zip for windows archives | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
|
||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- "^docs:" | ||
- "^test:" |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 WaterLemons2k | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,29 @@ | ||
# Autoindex CLI | ||
|
||
The command-line interface for [autoindex](https://github.com/go-autoindex/autoindex). | ||
|
||
## Installation | ||
|
||
### GitHub Releases | ||
|
||
[Download](https://github.com/go-autoindex/cli/releases) | ||
|
||
### `go install` | ||
|
||
```sh | ||
go install github.com/go-autoindex/cli/cmd/autoindex@latest | ||
``` | ||
|
||
## Usage | ||
|
||
```sh | ||
$ autoindex | ||
index.html | ||
|
||
$ autoindex -h | ||
Usage of ./autoindex: | ||
-dir string | ||
directory to index (default ".") | ||
-dry | ||
dry run | ||
``` |
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,35 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/go-autoindex/autoindex" | ||
"github.com/go-autoindex/cli/internal/path" | ||
) | ||
|
||
// flags represents the command line flags | ||
type flags struct { | ||
// dir is the directory to index | ||
dir string | ||
} | ||
|
||
var ( | ||
dir = flag.String("dir", ".", "directory to index") | ||
dry = flag.Bool("dry", false, "dry run") | ||
) | ||
|
||
// parseFlags parses the command line flags. | ||
func parseFlags() *flags { | ||
flag.Parse() | ||
|
||
if *dry { | ||
fmt.Fprintln(os.Stderr, "dry run") | ||
autoindex.Opts.Dry = true | ||
} | ||
|
||
return &flags{ | ||
dir: path.JoinDir(*dir), | ||
} | ||
} |
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,15 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/go-autoindex/autoindex" | ||
"github.com/go-autoindex/cli/internal/path" | ||
) | ||
|
||
func main() { | ||
flags := parseFlags() | ||
autoindex.Opts.Root = flags.dir | ||
|
||
if err := path.WalkAndIndex(flags.dir); err != nil { | ||
panic(err) | ||
} | ||
} |
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,6 @@ | ||
module github.com/go-autoindex/cli | ||
|
||
// The minimum version of windows/arm64 support. | ||
go 1.17 | ||
|
||
require github.com/go-autoindex/autoindex v1.0.1 |
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 @@ | ||
github.com/go-autoindex/autoindex v1.0.1 h1:FEgggK5ujaSGJ/kiG53mG6WFDXs0weu6O/7P43b8bcc= | ||
github.com/go-autoindex/autoindex v1.0.1/go.mod h1:9hV11G2rxfXSlj1cya6tLd9GQhpKp09WZ7LpaHpW11o= |
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,8 @@ | ||
package path | ||
|
||
import "path" | ||
|
||
// JoinDir is a wrapper around [path.Join], and adds a trailing slash. | ||
func JoinDir(elems ...string) string { | ||
return path.Join(elems...) + "/" | ||
} |
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,22 @@ | ||
package path | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/go-autoindex/autoindex" | ||
) | ||
|
||
// ignored reports whether path should be ignored | ||
func ignored(path string) bool { | ||
return isIndex(path) || isDot(path) | ||
} | ||
|
||
// isDot checks if the given path is a dot file. | ||
func isDot(path string) bool { | ||
return strings.HasPrefix(path, ".") | ||
} | ||
|
||
// isIndex checks if the given path is "index.html". | ||
func isIndex(path string) bool { | ||
return path == autoindex.Index() | ||
} |
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,45 @@ | ||
package path | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/go-autoindex/autoindex" | ||
"github.com/go-autoindex/cli/internal/sort" | ||
) | ||
|
||
// WalkAndIndex walks through the directory and generates the index. | ||
func WalkAndIndex(dir string) error { | ||
entries, err := os.ReadDir(dir) | ||
if err != nil { | ||
return err | ||
} | ||
sort.DirFirst(entries) | ||
|
||
return autoindex.Gen(walk(dir, entries)) | ||
} | ||
|
||
// walk walks through the directory and generates info for the index. | ||
func walk(dir string, entries []os.DirEntry) autoindex.Info { | ||
info := autoindex.Info{ | ||
Dir: dir, | ||
Entries: make([]string, 0, len(entries)), | ||
} | ||
|
||
for _, entry := range entries { | ||
name := entry.Name() | ||
if ignored(name) { | ||
continue | ||
} | ||
|
||
if entry.IsDir() { | ||
// Mark name as a directory | ||
name = JoinDir(name) | ||
|
||
WalkAndIndex(JoinDir(dir, name)) | ||
} | ||
|
||
info.Entries = append(info.Entries, name) | ||
} | ||
|
||
return info | ||
} |
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,20 @@ | ||
package sort | ||
|
||
import ( | ||
"os" | ||
"sort" | ||
"strings" | ||
) | ||
|
||
// DirFirst sorts entries by directory first | ||
func DirFirst(entries []os.DirEntry) { | ||
sort.Slice(entries, func(i, j int) bool { | ||
// Directories first | ||
if entries[i].IsDir() != entries[j].IsDir() { | ||
return entries[i].IsDir() | ||
} | ||
|
||
// Case insensitive | ||
return strings.ToLower(entries[i].Name()) < strings.ToLower(entries[j].Name()) | ||
}) | ||
} |