mirror of
https://github.com/NohamR/papeer.git
synced 2026-05-25 20:00:47 +00:00
add ci (#2)
* add ci * format code * update go version * update go file * add kindlegen * update go file * update go file * test ci * multiline run * edit go file * fix tar * mv kindlegen to usr local bin
This commit is contained in:
15
.github/workflows/format.yml
vendored
Normal file
15
.github/workflows/format.yml
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
name: Format
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- '**.go'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
format:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Check formatting
|
||||||
|
run: if [[ -n "$(gofmt -l .)" ]]; then exit 1; fi
|
||||||
25
.github/workflows/test.yml
vendored
Normal file
25
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
name: Test
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- '**.go'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: 1.17
|
||||||
|
- name: Install kindlegen
|
||||||
|
run: |
|
||||||
|
curl -L https://github.com/lapwat/papeer/releases/download/kindlegen/kindlegen_linux_2.6_i386_v2_9.tar.gz > kindlegen.tar.gz
|
||||||
|
tar xzvf kindlegen.tar.gz
|
||||||
|
chmod +x kindlegen
|
||||||
|
mv kindlegen /usr/local/bin
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Test
|
||||||
|
run: make test
|
||||||
@@ -398,11 +398,11 @@ func GetLinks(url *urllib.URL, selector string, limit, offset int, reverse, incl
|
|||||||
selector = "a"
|
selector = "a"
|
||||||
selectorSet = false
|
selectorSet = false
|
||||||
}
|
}
|
||||||
|
|
||||||
pathLinks := map[string][]link{}
|
pathLinks := map[string][]link{}
|
||||||
pathCount := map[string]int{}
|
pathCount := map[string]int{}
|
||||||
pathMax = ""
|
pathMax = ""
|
||||||
|
|
||||||
// visit and count link classes
|
// visit and count link classes
|
||||||
c := colly.NewCollector()
|
c := colly.NewCollector()
|
||||||
c.OnHTML(selector, func(e *colly.HTMLElement) {
|
c.OnHTML(selector, func(e *colly.HTMLElement) {
|
||||||
@@ -410,34 +410,34 @@ func GetLinks(url *urllib.URL, selector string, limit, offset int, reverse, incl
|
|||||||
text := strings.TrimSpace(e.Text)
|
text := strings.TrimSpace(e.Text)
|
||||||
path := GetPath(e.DOM)
|
path := GetPath(e.DOM)
|
||||||
key := path
|
key := path
|
||||||
|
|
||||||
if selectorSet {
|
if selectorSet {
|
||||||
|
|
||||||
// if selector is set, we use the selector specified by the user
|
// if selector is set, we use the selector specified by the user
|
||||||
|
|
||||||
key = selector
|
key = selector
|
||||||
pathLinks[key] = append(pathLinks[key], NewLink(href, text))
|
pathLinks[key] = append(pathLinks[key], NewLink(href, text))
|
||||||
pathCount[key] += 1
|
pathCount[key] += 1
|
||||||
pathMax = key
|
pathMax = key
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// if selector is not set, we compute the selector ourselves
|
// if selector is not set, we compute the selector ourselves
|
||||||
|
|
||||||
class := e.Attr("class")
|
class := e.Attr("class")
|
||||||
// include the element class to make sure we have the same exact path for every link in the table of content
|
// include the element class to make sure we have the same exact path for every link in the table of content
|
||||||
key = fmt.Sprintf("%s.%s", path, class)
|
key = fmt.Sprintf("%s.%s", path, class)
|
||||||
|
|
||||||
// we count this key if the link text is not empty
|
// we count this key if the link text is not empty
|
||||||
if text != "" {
|
if text != "" {
|
||||||
pathLinks[key] = append(pathLinks[key], NewLink(href, text))
|
pathLinks[key] = append(pathLinks[key], NewLink(href, text))
|
||||||
pathCount[key] += len(text)
|
pathCount[key] += len(text)
|
||||||
|
|
||||||
if pathCount[key] > pathCount[pathMax] {
|
if pathCount[key] > pathCount[pathMax] {
|
||||||
pathMax = key
|
pathMax = key
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
c.Visit(url.String())
|
c.Visit(url.String())
|
||||||
|
|||||||
Reference in New Issue
Block a user