~bouncepaw/betula

betula: Refactoring: move states to const group of values v1 APPLIED

~danilax86: 1
 Refactoring: move states to const group of values

 1 files changed, 29 insertions(+), 25 deletions(-)
#1044913 .build.yml failed
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~bouncepaw/betula/patches/43857/mbox | git am -3
Learn more about email & git

[PATCH betula] Refactoring: move states to const group of values Export this patch

From: Danila Gorelko <danila@danilax86.space>

---
 readpage/workers.go | 54 ++++++++++++++++++++++++---------------------
 1 file changed, 29 insertions(+), 25 deletions(-)

diff --git a/readpage/workers.go b/readpage/workers.go
index 97050e7..f4ed747 100644
--- a/readpage/workers.go
+++ b/readpage/workers.go
@@ -7,26 +7,33 @@ import (
	"net/url"
)

const (
	stateLooking = iota
	stateFound
	stateFoundText
)

const (
	stateNotSure = iota
	stateSure
)

func listenForTitle(nodes chan *html.Node, data *FoundData) {
	state := 0
	// 0 looking
	// 1 found
	state := stateLooking
	for n := range nodes {
		if state == 0 {
		if state == stateLooking {
			if n.Type == html.ElementNode && n.Data == "title" {
				data.title = n.FirstChild.Data
				state = 1
				state = stateFound
			}
		}
	}
}

func listenForBookmarkOf(nodes chan *html.Node, data *FoundData) {
	state := 0
	// 0 looking
	// 1 found
	state := stateLooking
	for n := range nodes {
		if state == 1 {
		if state == stateFound {
			continue
		}

@@ -48,25 +55,22 @@ func listenForBookmarkOf(nodes chan *html.Node, data *FoundData) {
			}

			data.BookmarkOf = uri
			state = 1
			state = stateFound
		}
	}
}

func listenForPostName(nodes chan *html.Node, data *FoundData) {
	state := 0
	// 0 nothing found yet
	// 1 found a p-name
	// 2 found the p-name's text
	state := stateLooking
	for n := range nodes {
		switch {
		case state == 2:
		case state == stateFoundText:
			continue
		case state == 1 && n.Type == html.TextNode:
		case state == stateFound && n.Type == html.TextNode:
			data.PostName = n.Data
			state = 2
		case state == 0 && nodeHasClass(n, "p-name"):
			state = 1
			state = stateFoundText
		case state == stateLooking && nodeHasClass(n, "p-name"):
			state = stateFound
		}
	}
}
@@ -81,9 +85,9 @@ func listenForTags(nodes chan *html.Node, data *FoundData) {
}

func listenForMycomarkup(nodes chan *html.Node, data *FoundData) {
	state := 0 // 0 looking 1 found
	state := stateLooking
	for n := range nodes {
		if state == 1 {
		if state == stateFound {
			continue
		}

@@ -124,22 +128,22 @@ func listenForMycomarkup(nodes chan *html.Node, data *FoundData) {
}

func listenForHFeed(nodes chan *html.Node, data *FoundData) {
	state := 0 // 0 not sure 1 sure
	state := stateNotSure
	for n := range nodes {
		if state == 1 {
		if state == stateSure {
			continue
		}

		if nodeHasClass(n, "h-feed") {
			data.IsHFeed = true
			state = 1
			state = stateSure
			continue
		}

		// If we've found an h-entry, then it's highly-highly unlikely that the
		// document is an h-feed. At least in Betula.
		if nodeHasClass(n, "h-entry") {
			state = 1
			state = stateSure
		}
	}
}
-- 
2.38.5
betula/patches/.build.yml: FAILED in 2m50s

[Refactoring: move states to const group of values][0] from [~danilax86][1]

[0]: https://lists.sr.ht/~bouncepaw/betula/patches/43857
[1]: mailto:danila@danilax86.space

✗ #1044913 FAILED betula/patches/.build.yml https://builds.sr.ht/~bouncepaw/job/1044913
LGTM. Applied. Thanks!