awesomefw

package module
v0.0.0-...-8c5d228 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2023 License: MIT Imports: 16 Imported by: 0

README

Build Status CodeCov Go Report Card CII Best Practices Godoc License MIT

Awesome Framework

This is a framework for creating Awesome lists. See it in action at a fork of awesome-go

It can convert different filetypes into each other and fetch metadata about the repositories mentioned.

awesome.yml

awesome.yml:

#!/usr/bin/env awesome compile --config

lists:
- input: "inplist.md"
  format: "md:list"
  outputs:
  - file:   "outlist.md"
    format: "md:table+meta"
  - file:   "index.html"
    format: "html:table+meta"
  - file:   "/dev/stdout"
    format: "test-alpha"

post-build.awesome.sh:

#!/bin/bash

mkdir -p public
cp -r tmpl/** public

cat <<-EOF > public/index.html
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
    </head>
    <body>
        $(cat public/index.html)
    </body>
</html>
EOF

Filetypes

md:list (Input)
+ lots
+ of
+ markdown
* [<name>](<url>) - <desc>
* [<name>](<url>) - <desc>

## Another Category

TODO: describe parameters

tabsep (Input/Output)
"literal line
'literal without newline
" continuation of previous line
<name>\t<url>\t<desc>
"""
block literal
which spans over
multiple lines
"""

TODO: describe parameters

md:table (+ >html) (Output)
| Name            | Desc   |
|-----------------|--------|
| [<name>](<url>) | <desc> |

If you append >html the markdown will be compiled with Blackfriday.

md:table+meta (+ >html) (Output)
| Stars   | Forks   | Issues   | Last Commit   | Name            | Desc   |
|---------|---------|----------|---------------|-----------------|--------|
| <stars> | <forks> | <issues> | <last commit> | [<name>](<url>) | <desc> |

If you append >html the markdown will be compiled with Blackfriday.

html:table+meta (Output)
<html>
	<head>
		<meta charset="UTF-8">
	</head>
	<body>
		<main>
<table><thead><tr><th>Stars</th><th>Forks</th><th>Issues</th><th>Last Commit</th><th>Name</th><th>Desc</th></tr></thead><tbody>
<tr><td>&lt;Stars&gt;</td><td>&lt;Forks&gt;</td><td>&lt;Issues&gt;</td><td>&lt;Last Commit&gt;</td><td><a href="&lt;url&gt;">&lt;Name&gt;</a></td><td>&lt;Desc&gt;</td></tr>
</tbody></table>
		</main>
	</body>
</html>
test:alpha (Test)

Tests whether the items are in alphabetically order.

Fetch Metadata

Data Sources:

Fetched Metadata:

  • Stars
  • Forks
  • Issues
  • Last Commit

Documentation

Index

Constants

View Source
const NA = "N/A"

Just N/A

Variables

View Source
var NameUrlDescTabSepPattern = []string{"name", "url", "desc"}

Functions

func Compile

func Compile(in io.Reader, size int, w io.Writer, inFF Input, outFF Output, apis *ApisCfg)

Parses the file conforming to inFF and writes the output of outFF to out. The size argument is used to provide a progressbar. The apis config is forwarded to FetchMeta.

func CompileFile

func CompileFile(inpPath string, w io.Writer, inFF Input, outFF Output, apis *ApisCfg)

Opens the file and runs Compile

func ExecuteConfig

func ExecuteConfig(data []byte, apis *ApisCfg) []error

func ExecuteConfigFile

func ExecuteConfigFile(f string, apis *ApisCfg) []error

Types

type ApiCfg

type ApiCfg struct {
	// This is an access token passed to the API
	// NOTE: Make sure your access tokens aren't in the source code.
	AccessToken string

	// This variable specifies how many requests should be made to the API before falling back to a default response.
	// NOTE: This should only be used for development purposes.
	MaxRequests int
}

This is used by FetchMeta to get the access token and the maximum number of requests for any given API.

type ApisCfg

type ApisCfg struct {
	UseProgressBar bool
	GitHubCfg      *ApiCfg
	GitLabCfg      *ApiCfg
}

This holds ApiCfgs for each API used by FetchMeta

func GetApisFromEnv

func GetApisFromEnv(prefix string) (*ApisCfg, error)

func NewDebugCfg

func NewDebugCfg() *ApisCfg

func NewDebugReqsApisCfg

func NewDebugReqsApisCfg() *ApisCfg

type Ctx

type Ctx struct {

	// This is the API config passed to FetchMeta
	ApisCfg *ApisCfg
	// contains filtered or unexported fields
}

This is the context that is passed between Input, Output and FetchMeta.

func NewCtx

func NewCtx(apis *ApisCfg) *Ctx

func NewDebugCtx

func NewDebugCtx() *Ctx

type Input

type Input interface {
	// This function should parse a line and call either out.Item() or out.Literal()
	ParseLine(w io.Writer, l string, out Output, ctx *Ctx)
}

The file format according to which the input will be parsed.

func InputByName

func InputByName(name string) (Input, error)

func InputMarkdown

func InputMarkdown(sep string) Input

Parses the code according to this pattern:

  • [<name>](<url>) - <desc>
  • [<name>](<url>) - <desc>

sep: " - "

func InputTabSep

func InputTabSep(fields []string) Input

Parses the code according to this pattern:

<name>\t<url>\t<desc>
"literal line
'literal without newline
" continuation of previous line
 """
block literal
which spans over
multiple lines
"""

type Item

type Item struct {
	Name    string
	Url     string
	RepoUrl string
	Desc    string
}

An Item usually consists at least of a name, url and description

type Meta

type Meta interface {
	// The number of stars or N/A
	Stars() string

	// The number of forks or N/A
	Forks() string

	// The number of issues or N/A
	Issues() string

	// The date of the last commit or N/A
	LastCommit() string

	// File returns the URL under which the given path may be found or "".
	// There must not be any checks whether the file actually exists.
	File(path string) string
}

Metadata about a repository

func FetchMeta

func FetchMeta(url string, ctx *Ctx) Meta

Fetches a Meta object from the APIs For supported URL schemas see the tests in meta_test.go/TestFetchMeta()

type Output

type Output interface {
	// This should write the literal l to out
	Literal(w io.Writer, l string, ctx *Ctx)

	// This should write the formatted item to out
	Item(w io.Writer, item *Item, ctx *Ctx)

	// This function is called to initialize the Output
	Start(w io.Writer, ctx *Ctx)

	// This function is called to teardown the Output
	End(w io.Writer, ctx *Ctx)
}

The output file format

func OutputBlackfriday

func OutputBlackfriday(prev Output, opts ...blackfriday.Option) Output

func OutputByName

func OutputByName(name string) (Output, error)

func OutputHtml

func OutputHtml() Output

func OutputMarkdown

func OutputMarkdown() Output

Prints the code according to this pattern:

| Stars | Forks | Issues | Last Commit | Name | Desc | |---------|---------|----------|---------------|-----------------|--------| | <stars> | <forks> | <issues> | <last commit> | [<name>](<url>) | <desc> |

func OutputMarkdownHtml

func OutputMarkdownHtml() Output

Same as OutputMarkdown but compiled to HTML by github.com/russross/blackfriday/v2

func OutputSimpleMarkdown

func OutputSimpleMarkdown() Output

Prints the code according to this pattern:

| Name | Desc | |-----------------|--------| | [<name>](<url>) | <desc> |

func OutputSimpleMarkdownHtml

func OutputSimpleMarkdownHtml() Output

Same as OutputSimpleMarkdown but compiled to HTML by github.com/russross/blackfriday/v2

func OutputTabSep

func OutputTabSep(fields []string) Output

Prints the code according to this pattern:

<name>\t<url>\t<desc>
"literal line
'literal without newline
" continuation of previous line
"block literal
"which spans over
"multiple lines

func OutputTestAlphabetical

func OutputTestAlphabetical() Output

Panics if the items aren't alphabetically sorted. Nothing is written to out

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL