mirror of
https://github.com/hahwul/WebHackersWeapons.git
synced 2025-02-22 16:09:54 -05:00
add generating tool
This commit is contained in:
parent
6a48ca389a
commit
2995bb3b3e
79
weapon-md.go
Normal file
79
weapon-md.go
Normal file
@ -0,0 +1,79 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"golang.org/x/net/html"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
/*
|
||||
template
|
||||
| [WebHackersWeapons](https://github.com/hahwul/WebHackersWeapons) | template |  |  | <br> <br>  <br>  |
|
||||
*/
|
||||
|
||||
func isTitleElement(n *html.Node) bool {
|
||||
return n.Type == html.ElementNode && n.Data == "title"
|
||||
}
|
||||
|
||||
func traverse(n *html.Node) (string, bool) {
|
||||
if isTitleElement(n) {
|
||||
return n.FirstChild.Data, true
|
||||
}
|
||||
|
||||
for c := n.FirstChild; c != nil; c = c.NextSibling {
|
||||
result, ok := traverse(c)
|
||||
if ok {
|
||||
return result, ok
|
||||
}
|
||||
}
|
||||
|
||||
return "", false
|
||||
}
|
||||
|
||||
func GetHtmlTitle(r io.Reader) (string, bool) {
|
||||
doc, err := html.Parse(r)
|
||||
if err != nil {
|
||||
panic("Fail to parse html")
|
||||
}
|
||||
|
||||
return traverse(doc)
|
||||
}
|
||||
|
||||
func main() {
|
||||
repourl := flag.String("url", "", "github / gitlab / bitbucket url")
|
||||
first := flag.Bool("isFirst", false, "if you add new type, it use")
|
||||
flag.Parse()
|
||||
if flag.NFlag() == 0 {
|
||||
flag.Usage()
|
||||
return
|
||||
}
|
||||
u, err := url.Parse(*repourl)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
//fmt.Println(u.Path)
|
||||
name := strings.Split(u.Path, "/")[2]
|
||||
//fmt.Println(name)
|
||||
desc := "asdf"
|
||||
resp, err := http.Get(*repourl)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if title, ok := GetHtmlTitle(resp.Body); ok {
|
||||
desc = strings.Split(string(title), ": ")[1]
|
||||
} else {
|
||||
println("Fail to get HTML title")
|
||||
}
|
||||
if *first {
|
||||
fmt.Println("| Name | Description | Popularity | Language | Metadata |")
|
||||
fmt.Println("| ---------- | :---------- | :----------: | :----------: | :----------: |")
|
||||
}
|
||||
fmt.Println("| [" + name + "](" + *repourl + ") | " + desc + " |  |  | <br> <br>  <br>  |")
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user