Skip to content

Commit

Permalink
blog: also rewrite image links
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagokokada committed Jul 30, 2024
1 parent 5aceedb commit 1e9118b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
12 changes: 4 additions & 8 deletions 2024-07-30/01-first-impressions-fpgbc.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ Cable](https://en.wikipedia.org/wiki/Game_Link_Cable) (I don't have another
Game Boy to test). Sadly it is missing the infrared sensor, but the usage of
that was pretty limited anyway.

<!-- PXL_20240729_175245569 -->
[![FPGBC running Tetris.](https://capivaras.dev/images/1545d11f.jpeg)](https://capivaras.dev/images/1545d11f.jpeg)
[![FPGBC running Tetris.](/2024-07-30/PXL_20240729_175245569.jpg)](/2024-07-30/PXL_20240729_175245569.jpg)

<!-- PXL_20240729_175131157 -->
[![Back of FPGBC. It includes even reproduction stickers of the original.](https://capivaras.dev/images/6746624f.jpeg)](https://capivaras.dev/images/6746624f.jpeg)
[![Back of FPGBC. It includes even reproduction stickers of the original.](/2024-07-30/PXL_20240729_175131157.jpg)](/2024-07-30/PXL_20240729_175131157.jpg)

So how well does it work? I can't say for sure. I don't have any original games
with me, so I am relying in backups and a
Expand Down Expand Up @@ -72,8 +70,7 @@ came back to life.
About the features of the device: if you press the volume button (yes, you can
press it now), it opens the following menu:

<!-- PXL_20240729_210604830 -->
[![FPGBC menu.](https://capivaras.dev/images/4391c351.jpeg)](https://capivaras.dev/images/4391c351.jpeg)
[![FPGBC menu.](/2024-07-30/PXL_20240729_210604830.jpg)](/2024-07-30/PXL_20240729_210604830.jpg)

The first 2 features are the LCD backlight and volume. I didn't talk about
those, but the LCD screen seems to be IPS, and the quality is really good, and
Expand Down Expand Up @@ -147,5 +144,4 @@ gift, and I will buy another one soon. Can't wait to play [Pokémon
Gold](https://en.wikipedia.org/wiki/Pok%C3%A9mon_Gold_and_Silver) in (almost)
original hardware again.

<!-- PXL_20240729_123847458 -->
[![The kit before assemble.](https://capivaras.dev/images/7f34caba.jpeg)](https://capivaras.dev/images/7f34caba.jpeg)
[![The kit before assemble.](/2024-07-30/PXL_20240729_123847458.jpg)](/2024-07-30/PXL_20240729_123847458.jpg)
8 changes: 5 additions & 3 deletions blog.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ import (
"github.com/yuin/goldmark"
)

const blogBaseUrl = "https://github.com/thiagokokada/blog/blob/main"
const blogBaseUrl= "https://github.com/thiagokokada/blog"
const blogMainUrl = blogBaseUrl + "/blob/main"
const blogRawUrl = blogBaseUrl + "/raw/main"
const readmeTemplate = `# Blog
Mirror of my blog in https://kokada.capivaras.dev/.
Expand Down Expand Up @@ -147,12 +149,12 @@ func genRss(posts posts) string {
Title: "kokada's blog",
Description: "# dd if=/dev/urandom of=/dev/brain0",
}
md := goldmark.New(goldmark.WithExtensions(NewLinkRewriter(blogBaseUrl, nil)))
md := goldmark.New(goldmark.WithExtensions(NewLinkRewriter(blogMainUrl, nil)))

var items []*feeds.Item
for el := posts.Back(); el != nil; el = el.Prev() {
post := el.Value
link := must1(url.JoinPath(blogBaseUrl, el.Key))
link := must1(url.JoinPath(blogMainUrl, el.Key))
var buf bytes.Buffer
must(md.Convert(post.contents, &buf))
items = append(items, &feeds.Item{
Expand Down
17 changes: 17 additions & 0 deletions link_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func (e *linkRewriter) Transform(node *ast.Document, reader text.Reader, pc pars
if link, ok := n.(*ast.Link); ok {
e.rewriteLink(link)
}
if image, ok := n.(*ast.Image); ok {
e.rewriteImage(image)
}
return ast.WalkContinue, nil
})
}
Expand Down Expand Up @@ -81,3 +84,17 @@ func (e *linkRewriter) rewriteLink(l *ast.Link) {
}
}
}

// rewriteImage modifies the image URL
func (e *linkRewriter) rewriteImage(i *ast.Image) {
image := string(i.Destination)

if strings.HasPrefix(image, ".") {
log.Printf("[WARN]: relative image link reference found: %s\n", image)
}

if strings.HasPrefix(image, "/") {
dest := must1(url.JoinPath(blogRawUrl, image))
i.Destination = []byte(dest)
}
}
Loading

0 comments on commit 1e9118b

Please sign in to comment.