Skip to content

Commit

Permalink
make the relative links work on GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
quantonganh committed Aug 27, 2023
1 parent 66088fb commit 15e0f00
Show file tree
Hide file tree
Showing 132 changed files with 37 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
- name: Build
run: CGO_ENABLED=0 GOARCH=arm64 go build -o blog -v -ldflags="-s -w" cmd/blog/main.go

- name: Create an archive containing the posts
run: find . -type d -maxdepth 1 -name '20[0-9][0-9]' | tar -cJf posts.tar.xz -T -

- name: Set up QEMU
if: github.event_name == 'push'
uses: docker/setup-qemu-action@v1
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This post recaps previous series of posts about Helix.

#### 1. Running code {#running-code}

In my [previous post](/2023/07/14/run-code-in-helix), I shared a method for running code from within Helix by using [this PR](https://github.com/helix-editor/helix/pull/6979).
In my [previous post](/2023/07/14/run-code-in-helix.md), I shared a method for running code from within Helix by using [this PR](https://github.com/helix-editor/helix/pull/6979).

I later discovered another useful trick [here](https://www.reddit.com/r/HelixEditor/comments/13x9a3z/integrating_fuzzylive_grepping_into_helix_my/). We can use [wezterm cli get-text](https://wezfurlong.org/wezterm/cli/cli/get-text.html) command to extract the filename and line number from the status line:

Expand All @@ -40,11 +40,11 @@ line_number=$(echo $status_line | awk '{ print $2}')

#### 2. Jumping to build errors {#jumping-to-build-errors}

- [/2023/07/21/jump-to-build-error-helix](/2023/07/21/jump-to-build-error-helix)
- [/2023/07/21/jump-to-build-error-helix](/2023/07/21/jump-to-build-error-helix.md)

#### 3. Quickly select a command and open it in a new pane {#quickly-select-a-command-and-open-it-in-a-new-pane}

- [/2023/08/04/quick-select-wezterm](/2023/08/04/quick-select-wezterm)
- [/2023/08/04/quick-select-wezterm](/2023/08/04/quick-select-wezterm.md)

#### 4. Testing a single function {#testing-a-single-function}

Expand Down Expand Up @@ -79,7 +79,7 @@ While Helix currently [does not support Git](https://github.com/helix-editor/hel
;;
```

and [reload automatically](/2023/07/25/auto-reload-helix) after switching back.
and [reload automatically](/2023/07/25/auto-reload-helix.md) after switching back.

##### git blame

Expand All @@ -94,7 +94,7 @@ Since we can obtain the filename and line number, we can easily send it to [tig]

#### 6. File tree {#file-tree}

- [/2023/08/02/file-tree-workaround-for-helix](/2023/08/02/file-tree-workaround-for-helix)
- [/2023/08/02/file-tree-workaround-for-helix](/2023/08/02/file-tree-workaround-for-helix.md)

Discover how to open [broot](https://github.com/Canop/broot) from within Helix:

Expand Down Expand Up @@ -136,12 +136,12 @@ wezterm cli activate-pane-direction --pane-id $pane_id right

#### 7. Creating snippets {#creating-snippets}

- [/2023/07/31/create-snippets-in-helix](/2023/07/31/create-snippets-in-helix)
- [/2023/07/31/create-snippets-in-helix](/2023/07/31/create-snippets-in-helix.md)

#### 8. How to debug? {#how-to-debug}

- [Debugging Rust in Helix](https://quantonganh.com/2023/08/10/debug-rust-helix)
- [Debugging Rust in Helix (Part 2)](https://quantonganh.com/2023/08/11/debug-rust-helix-2)
- [Debugging Rust in Helix](https://quantonganh.com/2023/08/10/debug-rust-helix.md)
- [Debugging Rust in Helix (Part 2)](https://quantonganh.com/2023/08/11/debug-rust-helix-2.md)

I submitted [this PR](https://github.com/helix-editor/helix/pull/7936) to allow the `target` directory to appear in the completion list in the debugger prompt, and it got merged so quickly.

Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FROM alpine:3.13
WORKDIR /app
RUN apk add --no-cache ca-certificates
COPY posts posts
COPY about.md projects.md resume.md ./
ADD posts.tar.xz .
RUN mkdir db
COPY blog .
EXPOSE 80
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions cmd/blog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {
}

viper.SetDefault("http.addr", ":80")
viper.SetDefault("posts.dir", "posts")
viper.SetDefault("posts.dir", ".")

var config *blog.Config
if err := viper.Unmarshal(&config); err != nil {
Expand Down Expand Up @@ -81,7 +81,7 @@ type app struct {
}

func newApp(config *blog.Config, posts []*blog.Post) *app {
indexPath := path.Join(path.Dir(config.Posts.Dir), path.Base(config.Posts.Dir)+".bleve")
indexPath := path.Join(path.Dir(config.Posts.Dir), "posts.bleve")
httpServer, err := http.NewServer(config, posts, indexPath)
if err != nil {
log.Fatalf("%+v\n", err)
Expand Down
2 changes: 1 addition & 1 deletion http/category_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ func TestCategoryHandler(t *testing.T) {
s.router.ServeHTTP(rr, request)

assert.Equal(t, http.StatusOK, rr.Code)
assert.Equal(t, "/2019/09/19/test", getLinkByText(t, rr.Body, "Test"))
assert.Equal(t, "/2019/09/19/test.md", getLinkByText(t, rr.Body, "Test"))
}
2 changes: 1 addition & 1 deletion http/photos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestPhotosHandler(t *testing.T) {
s.router.ServeHTTP(rr, request)

assert.Equal(t, http.StatusOK, rr.Code)
assert.Equal(t, "/2019/09/19/test", getLinkByImg(t, rr.Body, "/path/to/photo.jpg"))
assert.Equal(t, "/2019/09/19/test.md", getLinkByImg(t, rr.Body, "/path/to/photo.jpg"))
}

func getLinkByImg(t *testing.T, body *bytes.Buffer, imgSrc string) string {
Expand Down
10 changes: 7 additions & 3 deletions http/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import (

func (s *Server) postHandler(postsDir string) appHandler {
return func(w http.ResponseWriter, r *http.Request) error {
if hasSuffix(r.URL.Path, []string{"jpg", "jpeg", "png", "gif"}) {
http.ServeFile(w, r, path.Join(postsDir, r.URL.Path))
uriPath := r.URL.Path
if hasSuffix(uriPath, []string{"jpg", "jpeg", "png", "gif"}) {
http.ServeFile(w, r, path.Join(postsDir, uriPath))
} else {
currentPost := s.PostService.GetPostByURI(r.URL.Path)
if !strings.HasSuffix(uriPath, ".md") {
uriPath += ".md"
}
currentPost := s.PostService.GetPostByURI(uriPath)
if currentPost == nil {
return &Error{
Message: "post not found",
Expand Down
2 changes: 1 addition & 1 deletion http/post_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ func testPostHandler(t *testing.T, url string) {
s.router.ServeHTTP(rr, request)

assert.Equal(t, http.StatusOK, rr.Code)
assert.Equal(t, "/2019/09/19/test", getLinkByText(t, rr.Body, "Test"))
assert.Equal(t, "/2019/09/19/test.md", getLinkByText(t, rr.Body, "Test"))
}
2 changes: 1 addition & 1 deletion http/rss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ func TestRSSHandler(t *testing.T) {
var rss *feeds.RssFeedXml
require.NoError(t, xml.NewDecoder(rr.Body).Decode(&rss))
assert.Equal(t, 1, len(rss.Channel.Items))
assert.Equal(t, "http://localhost/2019/09/19/test", rss.Channel.Items[0].Link)
assert.Equal(t, "http://localhost/2019/09/19/test.md", rss.Channel.Items[0].Link)
}
3 changes: 2 additions & 1 deletion http/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Test.`)
if err != nil {
log.Fatal(err)
}
fmt.Printf("post: %+v", post)

s, err = NewServer(cfg, []*blog.Post{post}, indexPath)
if err != nil {
Expand Down Expand Up @@ -142,7 +143,7 @@ func TestSearchHandler(t *testing.T) {
s.router.ServeHTTP(rr, request)

assert.Equal(t, http.StatusOK, rr.Code)
assert.Equal(t, "/2019/09/19/test", getLinkByText(t, rr.Body, "Test"))
assert.Equal(t, "/2019/09/19/test.md", getLinkByText(t, rr.Body, "Test"))

t.Cleanup(func() {
_ = os.RemoveAll(indexPath)
Expand Down
2 changes: 1 addition & 1 deletion http/sitemap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ func TestSitemapHandler(t *testing.T) {
require.NoError(t, xml.NewDecoder(rr.Body).Decode(&sitemap))
assert.Equal(t, 2, len(sitemap.URLs))
assert.Equal(t, "http://localhost", sitemap.URLs[0].Loc)
assert.Equal(t, "http://localhost/2019/09/19/test", sitemap.URLs[1].Loc)
assert.Equal(t, "http://localhost/2019/09/19/test.md", sitemap.URLs[1].Loc)
}
11 changes: 7 additions & 4 deletions markdown/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package markdown

import (
"context"
"fmt"
"html/template"
"io"
"net/url"
Expand All @@ -17,6 +18,7 @@ import (
"github.com/alecthomas/chroma/formatters/html"
"github.com/alecthomas/chroma/styles"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
bf "github.com/russross/blackfriday/v2"
"golang.org/x/sync/errgroup"
"gopkg.in/yaml.v2"
Expand All @@ -32,6 +34,7 @@ const (
summaryLength = 70
threeBackticks = "```"
numberOfRelatedPosts = 5
mdExtension = ".md"
)

// GetAllPosts gets all posts in root directory
Expand All @@ -44,7 +47,7 @@ func GetAllPosts(root string) ([]*blog.Post, error) {
if err != nil {
return err
}
if filepath.Ext(path) != ".md" {
if filepath.Ext(path) != mdExtension {
return nil
}
select {
Expand Down Expand Up @@ -166,16 +169,16 @@ func Parse(ctx context.Context, root string, r io.Reader) (*blog.Post, error) {

p := blog.Post{}
if err := yaml.Unmarshal([]byte(metadata), &p); err != nil {
return nil, errors.Wrapf(err, "failed to decode metadata")
log.Printf("failed to decode metadata: %v", err)
}

switch v := r.(type) {
case *os.File:
name := v.Name()
basename := filepath.Base(name)
p.URI = path.Join(strings.TrimPrefix(filepath.Dir(name), root), strings.TrimSuffix(basename, filepath.Ext(basename)))
p.URI = path.Join(strings.TrimPrefix(filepath.Dir(name), root), basename)
default:
p.URI = path.Join(p.Date.GetYear(), p.Date.GetMonth(), p.Date.GetDay(), url.QueryEscape(strings.ToLower(p.Title)))
p.URI = path.Join(p.Date.GetYear(), p.Date.GetMonth(), p.Date.GetDay(), fmt.Sprintf("%s%s", url.QueryEscape(strings.ToLower(p.Title)), mdExtension))
}
if !strings.HasPrefix(p.URI, "/") {
p.URI = "/" + p.URI
Expand Down
Binary file added posts.tar.xz
Binary file not shown.
File renamed without changes.
File renamed without changes.

0 comments on commit 15e0f00

Please sign in to comment.