diff options
| -rw-r--r-- | handler.go | 18 | ||||
| -rw-r--r-- | markup.go | 18 | 
2 files changed, 20 insertions, 16 deletions
@@ -1,14 +1,12 @@  package main  import ( -	"bufio"  	"os"  	"fmt"  	"io/ioutil"  	"net/http"  	"path/filepath"  	"regexp" -	"strings"  	"strconv"  ) @@ -23,18 +21,6 @@ type Recipe struct {  	Html	string  } -func titleFromMd(md string) string { -	scanner := bufio.NewScanner(strings.NewReader(md)) -	for scanner.Scan() { -		line := scanner.Text() -		cut, found := strings.CutPrefix(line, "# ") -		if (found) { -			return cut -		} -	} -	return "no title detected" -} -  func indexGet(w http.ResponseWriter, r *http.Request) {  	entries, err := os.ReadDir("data/storage/recipes") @@ -60,7 +46,7 @@ func indexGet(w http.ResponseWriter, r *http.Request) {  		recipes = append(recipes, Recipe{  			v.Name(), -			titleFromMd(string(data)), +			titleFromMarkup(string(data)),  			string(data),  			"",  		}) @@ -84,7 +70,7 @@ func recipeGet(w http.ResponseWriter, r *http.Request) {  	recipe := Recipe{  		idStr, -		titleFromMd(string(data)), +		titleFromMarkup(string(data)),  		string(data),  		"",  	} diff --git a/markup.go b/markup.go new file mode 100644 index 0000000..c0a6d45 --- /dev/null +++ b/markup.go @@ -0,0 +1,18 @@ +package main + +import ( +	"bufio" +	"strings" +) + +func titleFromMarkup(markup string) string { +	scanner := bufio.NewScanner(strings.NewReader(markup)) +	for scanner.Scan() { +		line := scanner.Text() +		cut, found := strings.CutPrefix(line, "# ") +		if found { +			return cut +		} +	} +	return "no title detected" +}  | 
