all repos — site @ dc14fea7036a018fdae10816f98cc788578fb9cb

source for my site, found at icyphox.sh

bin: add replace and reup scripts
Anirudh Oppiliappan x@icyphox.sh
Sat, 12 Feb 2022 18:52:22 +0530
commit

dc14fea7036a018fdae10816f98cc788578fb9cb

parent

fed1c0424ac19e1a4aeb7d2bf806bfe6a4c88242

2 files changed, 59 insertions(+), 0 deletions(-)

jump to
A bin/replace.go

@@ -0,0 +1,46 @@

+// replace -- in-place edit a post +// usage: replace [old string] [new string] + +package main + +import ( + "fmt" + "log" + "os" + "strings" +) + +const dir = "pages/blog/" + +func main() { + if len(os.Args) != 3 { + fmt.Println("usage: replace [old string] [new string]") + os.Exit(1) + } + + oldLine, newLine := os.Args[1], os.Args[2] + + posts, err := os.ReadDir(dir) + if err != nil { + log.Fatalln(err) + } + for _, p := range posts { + path := dir + p.Name() + input, err := os.ReadFile(path) + if err != nil { + log.Fatalln(err) + } + + lines := strings.Split(string(input), "\n") + for i, line := range lines { + if strings.Contains(line, oldLine) { + lines[i] = newLine + } + } + output := strings.Join(lines, "\n") + err = os.WriteFile(path, []byte(output), 644) + if err != nil { + log.Fatalln(err) + } + } +}
A bin/reup.sh

@@ -0,0 +1,13 @@

+#!/usr/bin/env bash + +export NO_CP=1 +for img in static/img/*; do + printf "uploading... $img: " + u="$(~/bin/up $img)" + printf "$u\n" + new="![]("$u")" + old="$img" + printf "replacing $old with $new... " + bin/replace "$old" "$new" + printf "done\n" +done