New templating
This commit is contained in:
parent
001b7c9f69
commit
5be5e84295
116
bitcoin.go
116
bitcoin.go
|
@ -1,116 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"html"
|
|
||||||
"io/ioutil"
|
|
||||||
"os/exec"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Command struct {
|
|
||||||
name string
|
|
||||||
description string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Group struct {
|
|
||||||
name string
|
|
||||||
commands []Command
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
first := run("help")
|
|
||||||
split := strings.Split(first, "\n")
|
|
||||||
|
|
||||||
groups := make([]Group, 0)
|
|
||||||
commands := make([]Command, 0)
|
|
||||||
lastGroupName := ""
|
|
||||||
|
|
||||||
for _, line := range split {
|
|
||||||
if len(line) > 0 {
|
|
||||||
if strings.HasPrefix(line, "== ") {
|
|
||||||
if len(commands) != 0 {
|
|
||||||
g := Group{
|
|
||||||
name: lastGroupName,
|
|
||||||
commands: commands,
|
|
||||||
}
|
|
||||||
groups = append(groups, g)
|
|
||||||
commands = make([]Command, 0)
|
|
||||||
}
|
|
||||||
lastGroupName = line[3 : len(line)-3]
|
|
||||||
} else {
|
|
||||||
name := strings.Split(line, " ")[0]
|
|
||||||
desc := run("help", name)
|
|
||||||
desc = html.EscapeString(desc)
|
|
||||||
comm := Command{
|
|
||||||
name: name,
|
|
||||||
description: desc,
|
|
||||||
}
|
|
||||||
commands = append(commands, comm)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g := Group{
|
|
||||||
name: lastGroupName,
|
|
||||||
commands: commands,
|
|
||||||
}
|
|
||||||
groups = append(groups, g)
|
|
||||||
|
|
||||||
menuStr := ""
|
|
||||||
for _, group := range groups {
|
|
||||||
menuStr += `
|
|
||||||
<div class="card">
|
|
||||||
<div class="card-header">
|
|
||||||
`
|
|
||||||
menuStr += group.name
|
|
||||||
menuStr += `
|
|
||||||
</div>
|
|
||||||
<div class="card-body">`
|
|
||||||
|
|
||||||
for _, command := range group.commands {
|
|
||||||
menuStr += `
|
|
||||||
<a href="`
|
|
||||||
menuStr += command.name
|
|
||||||
menuStr += `.html">`
|
|
||||||
menuStr += command.name
|
|
||||||
menuStr += `</a><br>`
|
|
||||||
}
|
|
||||||
|
|
||||||
menuStr += `
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<br>`
|
|
||||||
|
|
||||||
}
|
|
||||||
check(ioutil.WriteFile("tmp-menu.inc", []byte(menuStr), 0644))
|
|
||||||
|
|
||||||
runBash("cat start.inc index.inc mid.inc tmp-menu.inc end.inc | sed 's/XXX/Main page/' > index.html")
|
|
||||||
|
|
||||||
for _, group := range groups {
|
|
||||||
for _, command := range group.commands {
|
|
||||||
check(ioutil.WriteFile("tmp.inc", []byte(command.description), 0644))
|
|
||||||
runBash("cat start.inc tmp.inc mid.inc tmp-menu.inc end.inc | sed 's/XXX/" + command.name + "/' > " + command.name + ".html")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
runBash("rm tmp.inc")
|
|
||||||
runBash("rm tmp-menu.inc")
|
|
||||||
}
|
|
||||||
|
|
||||||
func check(e error) {
|
|
||||||
if e != nil {
|
|
||||||
panic(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func runBash(cmd string) {
|
|
||||||
check(exec.Command("bash", "-c", cmd).Run())
|
|
||||||
}
|
|
||||||
|
|
||||||
func run(args ...string) string {
|
|
||||||
out, err := exec.Command("/home/g/dev/bitcoind/bitcoin-0.16.0/bin/bitcoin-cli", args...).CombinedOutput()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(out)
|
|
||||||
}
|
|
20
mid.inc
20
mid.inc
|
@ -1,20 +0,0 @@
|
||||||
</pre>
|
|
||||||
<hr>
|
|
||||||
<p>
|
|
||||||
This is a website, created out of frustration with uncomplete and outdated Bitcoin Core RPC documentation online.
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
It was inspired by <a href="http://chainquery.com/bitcoin-api">ChainQuery</a>, which seems to be abandoned. These docs are even simplier, so they can be regenerated by anyone.
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Made by <a href="https://twitter.com/karel_3d">@karel_3d</a>; license of the docs is MIT (see <a href="https://github.com/bitcoin/bitcoin/">bitcoin repo</a>), license of the scripts and webpage is also MIT ((C) 2018 Karel Bilek) (<a href="https://github.com/bitcoin-rpc/bitcoin-rpc.github.io">github repo</a>)
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Bitcoin version: 0.16.0.
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Note that the RPC is from a regtest node (for completeness), so it includes some additional calls that a regular node doesn't have.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class="col-4 col-lg-3 col-xl-2">
|
|
||||||
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"html/template"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Command struct {
|
||||||
|
Name string
|
||||||
|
Description string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Group struct {
|
||||||
|
Name string
|
||||||
|
Commands []Command
|
||||||
|
}
|
||||||
|
|
||||||
|
type Document struct {
|
||||||
|
Command *Command
|
||||||
|
Groups []Group
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
first := run("help")
|
||||||
|
split := strings.Split(first, "\n")
|
||||||
|
|
||||||
|
groups := make([]Group, 0)
|
||||||
|
commands := make([]Command, 0)
|
||||||
|
lastGroupName := ""
|
||||||
|
|
||||||
|
for _, line := range split {
|
||||||
|
if len(line) > 0 {
|
||||||
|
if strings.HasPrefix(line, "== ") {
|
||||||
|
if len(commands) != 0 {
|
||||||
|
g := Group{
|
||||||
|
Name: lastGroupName,
|
||||||
|
Commands: commands,
|
||||||
|
}
|
||||||
|
groups = append(groups, g)
|
||||||
|
commands = make([]Command, 0)
|
||||||
|
}
|
||||||
|
lastGroupName = line[3 : len(line)-3]
|
||||||
|
} else {
|
||||||
|
name := strings.Split(line, " ")[0]
|
||||||
|
desc := run("help", name)
|
||||||
|
comm := Command{
|
||||||
|
Name: name,
|
||||||
|
Description: desc,
|
||||||
|
}
|
||||||
|
commands = append(commands, comm)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
g := Group{
|
||||||
|
Name: lastGroupName,
|
||||||
|
Commands: commands,
|
||||||
|
}
|
||||||
|
groups = append(groups, g)
|
||||||
|
|
||||||
|
tmpl := template.Must(template.ParseFiles("template.html"))
|
||||||
|
tmpl.Execute(open("../index.html"), Document{
|
||||||
|
Command: nil,
|
||||||
|
Groups: groups,
|
||||||
|
})
|
||||||
|
|
||||||
|
for _, group := range groups {
|
||||||
|
for _, command := range group.Commands {
|
||||||
|
tmpl.Execute(open("../"+command.Name+".html"), Document{
|
||||||
|
Command: &command,
|
||||||
|
Groups: groups,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func check(e error) {
|
||||||
|
if e != nil {
|
||||||
|
panic(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func open(path string) io.Writer {
|
||||||
|
f, err := os.Create(path)
|
||||||
|
// not closing, program will close sooner
|
||||||
|
check(err)
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
|
||||||
|
func run(args ...string) string {
|
||||||
|
out, err := exec.Command("/home/g/dev/bitcoind/bitcoin-0.16.0/bin/bitcoin-cli", args...).CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(out)
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=1200px, shrink-to-fit=yes">
|
||||||
|
<meta name="description" content="Bitcoin Core RPC Docs{{if .Command}} - {{.Command.Name}}{{end}}">
|
||||||
|
<meta name="author" content="">
|
||||||
|
|
||||||
|
<title>{{if .Command}}{{.Command.Name}} - {{end}}Bitcoin Core RPC Docs</title>
|
||||||
|
|
||||||
|
<link href="./bootstrap.min.css" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
<style>
|
||||||
|
.card-body {
|
||||||
|
font-size:80%;
|
||||||
|
padding-top: 0.5em;
|
||||||
|
}
|
||||||
|
pre {
|
||||||
|
word-break: break-word;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
|
||||||
|
<nav class="navbar navbar-dark bg-dark ">
|
||||||
|
<a class="navbar-brand" href="/">Bitcoin Core RPC docs</a>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<main role="main" class="container-fluid" style="margin-top: 1pc;">
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-8 col-lg-9 col-xl-10">
|
||||||
|
<h1>{{if .Command}}{{.Command.Name}} - {{end}}Bitcoin RPC</h1>
|
||||||
|
{{if .Command}}
|
||||||
|
<pre>{{.Command.Description}}</pre>
|
||||||
|
<hr>
|
||||||
|
{{end}}
|
||||||
|
<p>
|
||||||
|
This is a website, created out of frustration with uncomplete and outdated Bitcoin Core RPC documentation online.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
It was inspired by <a href="http://chainquery.com/bitcoin-api">ChainQuery</a>, which seems to be abandoned. These docs are even simplier, so they can be regenerated by anyone.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Made by <a href="https://twitter.com/karel_3d">@karel_3d</a>; license of the docs is MIT (see <a href="https://github.com/bitcoin/bitcoin/">bitcoin repo</a>), license of the scripts and webpage is also MIT ((C) 2018 Karel Bilek) (<a href="https://github.com/bitcoin-rpc/bitcoin-rpc.github.io">github repo</a>)
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Bitcoin version: 0.16.0.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Note that the RPC is from a regtest node (for completeness), so it includes some additional calls that a regular node doesn't have.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-4 col-lg-3 col-xl-2">
|
||||||
|
{{range .Groups}}
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
{{.Name}}
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
{{range .Commands}}
|
||||||
|
<a href="{{.Name}}.html">{{.Name}}</a>
|
||||||
|
<br>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main> <!-- /container -->
|
||||||
|
</body>
|
||||||
|
</html>
|
37
start.inc
37
start.inc
|
@ -1,37 +0,0 @@
|
||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta name="viewport" content="width=1200px, shrink-to-fit=yes">
|
|
||||||
<meta name="description" content="Bitcoin Core RPC Docs - XXX">
|
|
||||||
<meta name="author" content="">
|
|
||||||
|
|
||||||
<title>XXX - Bitcoin Core RPC Docs</title>
|
|
||||||
|
|
||||||
<!-- Bootstrap core CSS -->
|
|
||||||
<link href="./bootstrap.min.css" rel="stylesheet">
|
|
||||||
</head>
|
|
||||||
<style>
|
|
||||||
.card-body {
|
|
||||||
font-size:80%;
|
|
||||||
padding-top: 0.5em;
|
|
||||||
}
|
|
||||||
pre {
|
|
||||||
word-break: break-word;
|
|
||||||
white-space: pre-wrap;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
|
|
||||||
|
|
||||||
<nav class="navbar navbar-dark bg-dark ">
|
|
||||||
<a class="navbar-brand" href="/">Bitcoin Core RPC docs</a>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<main role="main" class="container-fluid" style="margin-top: 1pc;">
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-8 col-lg-9 col-xl-10">
|
|
||||||
<h1>XXX - Bitcoin RPC</h1>
|
|
||||||
<pre>
|
|
Loading…
Reference in New Issue