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 26, 2023
1 parent 66088fb commit 97e17d8
Show file tree
Hide file tree
Showing 126 changed files with 27 additions and 17 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
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM alpine:3.13
WORKDIR /app
RUN apk add --no-cache ca-certificates
COPY posts posts
ADD posts.tar.xz .
RUN mkdir db
COPY blog .
EXPOSE 80
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion 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
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
10 changes: 6 additions & 4 deletions markdown/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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 +33,7 @@ const (
summaryLength = 70
threeBackticks = "```"
numberOfRelatedPosts = 5
mdExtension = ".md"
)

// GetAllPosts gets all posts in root directory
Expand All @@ -44,7 +46,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 +168,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(), 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 97e17d8

Please sign in to comment.