Commit: aef6fd0d9cde79dfd8b63c3fad7829fbe72a92bf Parent: a4d6c2d1ceb019f93d3c6fabf34c81e61cfbba9d Author: Vi Grey Date: 2023-08-15 05:26 UTC Summary: Add %PAGE_PATH% token CHANGELOG.md | 10 ++++++++++ src/bergelmir.go | 2 +- src/http.go | 10 ++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9558c6..8b34ddb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) +## [0.0.22] - 2023-08-15 + +### Added + +- %PAGE\_PATH% token + +### Changed + +- bytes.ReplaceAll instead of regexp ReplaceAll for html layout + ## [0.0.21] - 2023-07-08 ### Added diff --git a/src/bergelmir.go b/src/bergelmir.go index 468a8c4..69d6d37 100644 --- a/src/bergelmir.go +++ b/src/bergelmir.go @@ -13,7 +13,7 @@ var ( ) const ( - VERSION = "0.0.21" + VERSION = "0.0.22" ) func init() { diff --git a/src/http.go b/src/http.go index 1a766a0..76a455c 100644 --- a/src/http.go +++ b/src/http.go @@ -20,9 +20,10 @@ const ( ) var ( - geminiContentRe = regexp.MustCompile(`(?m)^\s*%GEMINI_CONTENT%`) + pagePathToken = []byte("%PAGE_PATH%") + geminiContentToken = []byte("%GEMINI_CONTENT%") + titleToken = []byte("%TITLE%") gemtextSubscriptionRe = regexp.MustCompile(`^(\d{4}-\d{2}-\d{2})\s*-?\s*(.*)$`) - titleRe = regexp.MustCompile(`%TITLE%`) ) // Returns true if the subdomain is "text" or "www.text", otherwise @@ -74,8 +75,9 @@ func catchAll(w http.ResponseWriter, r *http.Request) { } htmlLayoutContent, err := os.ReadFile(layoutPath) handleErr(err, fmt.Sprintf("Unable to read Layout HTML file %s\n", layoutPath)) - htmlLayoutContent = titleRe.ReplaceAll(htmlLayoutContent, pageTitle) - htmlLayoutContent = geminiContentRe.ReplaceAll(htmlLayoutContent, bytes.ReplaceAll(content, []byte("$"), []byte("$$"))) + htmlLayoutContent = bytes.ReplaceAll(htmlLayoutContent, titleToken, pageTitle) + htmlLayoutContent = bytes.ReplaceAll(htmlLayoutContent, geminiContentToken, bytes.ReplaceAll(content, []byte("$"), []byte("$$"))) + htmlLayoutContent = bytes.ReplaceAll(htmlLayoutContent, pagePathToken, []byte(u)) w.Write(htmlLayoutContent) } else if urlExtension == "" { w.WriteHeader(http.StatusNotFound) gemini://vigrey.com/git/bergelmir/commit/aef6fd0d9cde79dfd8b63c3fad7829fbe72a92bf.txt

-- Leo's gemini proxy

-- Connecting to vigrey.com:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/plain; charset=UTF-8

-- Response ended

-- Page fetched on Mon May 20 17:22:11 2024