Skip to content

Commit

Permalink
Initial commit of working site
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakjois committed Aug 7, 2024
1 parent 18c3a35 commit ff4c52c
Show file tree
Hide file tree
Showing 11 changed files with 279 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/go-build-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Go Build and Deploy

on:
workflow_dispatch:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build-and-deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: '1.23.0-rc.2'

- name: Build
run: go build ./...

- name: Run
run: ./debugjois.dev

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2

- name: Upload to S3
run: ./upload.sh
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ go.work.sum

# env file
.env
scratch.html
build
debugjois.dev
12 changes: 12 additions & 0 deletions content/daily-notes/2024-08-06.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Claude artefact showing example usage of LangChainGo: [LangChainGo Code Snippet for Cleaning Audio Transcripts](https://claude.ai/chat/9177a99f-3c8a-48b5-b05d-672998f96a80) #ai #claude

Read Schools Brief of AI from _The Economist_ #ai

viper can read from a custom environment variable using `viper.BindEnv`, e.g. `viper.BindEnv("OPENAI_API_KEY)` will bind `openai_api_key` config to the environment variable. From: [viper package - github.com/spf13/viper - Go Packages](https://pkg.go.dev/github.com/spf13/viper#BindEnv) #go #viper

Use latest from `main` branch in `go.mod`:
```
go get github.com/tmc/langchaingo/llms@main
```

Langchain support in Podscript: [Use langchaingo by deepakjois · Pull Request #13 · deepakjois/podscript · GitHub](https://github.com/deepakjois/podscript/pull/13/files)
18 changes: 18 additions & 0 deletions content/daily-notes/2024-08-07.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
One chapter of Why Machines Learn

Rebank podcast about Agora: [Rebank: A New Approach to Stablecoins with Nick van Eck](https://sites.libsyn.com/88961/a-new-approach-to-stablecoins-with-nick-van-eck)

FT Big Read article about India's dependence on Chine: *TODO Find Article Link*

Waffle marks are interesting: [Waffle mark | Observable Plot](https://observablehq.com/plot/marks/waffle)

[Even a Little Alcohol Can Harm Your Health, Research Shows - The New York Times](https://www.nytimes.com/2023/01/13/well/mind/alcohol-health-effects.html)

A library that detects mimetype using the contents of a file/stream: [GitHub - gabriel-vasile/mimetype: A fast Golang library for media type and file extension detection, based on magic numbers](https://github.com/gabriel-vasile/mimetype/)

GOTOOLCHAIN environment variable can be used to run a different go version - [Go Toolchains - The Go Programming Language](https://go.dev/doc/toolchain)

goldmark hashtag parser: [GitHub - abhinav/goldmark-hashtag: Adds support for #hashtags to the Goldmark Markdown parser.](https://github.com/abhinav/goldmark-hashtag)

caddy local file server no-config: `caddy file-server --root <folder>`

3 changes: 3 additions & 0 deletions content/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
<h1>Coming Soon</h1>
</div>
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module github.com/deepakjois/debugjois.dev

go 1.23

require (
github.com/bitfield/script v0.22.1 // indirect
github.com/itchyny/gojq v0.12.13 // indirect
github.com/itchyny/timefmt-go v0.1.5 // indirect
github.com/yuin/goldmark v1.7.4 // indirect
mvdan.cc/sh/v3 v3.7.0 // indirect
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/bitfield/script v0.22.1 h1:DphxoC5ssYciwd0ZS+N0Xae46geAD/0mVWh6a2NUxM4=
github.com/bitfield/script v0.22.1/go.mod h1:fv+6x4OzVsRs6qAlc7wiGq8fq1b5orhtQdtW0dwjUHI=
github.com/itchyny/gojq v0.12.13 h1:IxyYlHYIlspQHHTE0f3cJF0NKDMfajxViuhBLnHd/QU=
github.com/itchyny/gojq v0.12.13/go.mod h1:JzwzAqenfhrPUuwbmEz3nu3JQmFLlQTQMUcOdnu/Sf4=
github.com/itchyny/timefmt-go v0.1.5 h1:G0INE2la8S6ru/ZI5JecgyzbbJNs5lG1RcBqa7Jm6GE=
github.com/itchyny/timefmt-go v0.1.5/go.mod h1:nEP7L+2YmAbT2kZ2HfSs1d8Xtw9LY8D2stDBckWakZ8=
github.com/yuin/goldmark v1.7.4 h1:BDXOHExt+A7gwPCJgPIIq7ENvceR7we7rOS9TNoLZeg=
github.com/yuin/goldmark v1.7.4/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
mvdan.cc/sh/v3 v3.7.0 h1:lSTjdP/1xsddtaKfGg7Myu7DnlHItd3/M2tomOcNNBg=
mvdan.cc/sh/v3 v3.7.0/go.mod h1:K2gwkaesF/D7av7Kxl0HbF5kGOd2ArupNTX3X44+8l8=
110 changes: 110 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package main

import (
"bytes"
"fmt"
"html/template"
"io"
"log"
"os"
"path/filepath"
"slices"

"github.com/bitfield/script"
"github.com/yuin/goldmark"
)

// Page represents the structure of a web page.
type Page struct {
Title string
Body template.HTML
}

func main() {
if err := generateSite(); err != nil {
log.Fatalf("Failed to generate site: %v", err)
}
}

func generateSite() error {
tmpl, err := template.ParseFiles("templates/shell.html")
if err != nil {
return fmt.Errorf("parse template: %w", err)
}

if err := generateIndexPage(tmpl); err != nil {
return fmt.Errorf("generate index page: %w", err)
}

if err := generateDailyNotesPage(tmpl); err != nil {
return fmt.Errorf("generate daily notes page: %w", err)
}

return nil
}

func generateIndexPage(tmpl *template.Template) error {
content, err := os.ReadFile("content/index.html")
if err != nil {
return fmt.Errorf("read index content: %w", err)
}

page := Page{
Title: "Coming Soon",
Body: template.HTML(content),
}

return renderPage(tmpl, "build/index.html", page)
}

func generateDailyNotesPage(tmpl *template.Template) error {
notes, err := script.ListFiles("content/daily-notes/*.md").Slice()
if err != nil {
return fmt.Errorf("list daily notes: %w", err)
}

var buf bytes.Buffer
for _, note := range slices.Backward(notes) {
if err := convertMarkdownToHTML(note, &buf); err != nil {
return fmt.Errorf("convert note %s: %w", note, err)
}
}

page := Page{
Title: "Daily Notes",
Body: template.HTML(buf.String()),
}

return renderPage(tmpl, "build/daily", page)
}

func convertMarkdownToHTML(filename string, w io.Writer) error {
content, err := os.ReadFile(filename)
if err != nil {
return fmt.Errorf("read file: %w", err)
}

if err := goldmark.Convert(content, w); err != nil {
return fmt.Errorf("convert markdown: %w", err)
}

return nil
}

func renderPage(tmpl *template.Template, outputPath string, page Page) error {
if err := os.MkdirAll(filepath.Dir(outputPath), 0755); err != nil {
return fmt.Errorf("create directory: %w", err)
}

f, err := os.Create(outputPath)
if err != nil {
return fmt.Errorf("create file: %w", err)
}
defer f.Close()

if err := tmpl.Execute(f, page); err != nil {
return fmt.Errorf("execute template: %w", err)
}

return nil
}
29 changes: 29 additions & 0 deletions sync-notes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

set -e

# Check if git repo is clean
if [[ -n $(git status -s) ]]; then
echo "Error: Git repository is not clean. Please commit or stash changes."
exit 1
fi

# Check if OBSIDIAN_REPO environment variable is set
if [[ -z "$OBSIDIAN_REPO" ]]; then
echo "Error: OBSIDIAN_REPO environment variable is not set."
exit 1
fi

# Rsync contents
rsync -av "$OBSIDIAN_REPO/daily/" content/daily-notes/

# Check if there are changes
if [[ -n $(git status -s) ]]; then
# Commit changes with date and time
current_datetime=$(date "+%Y-%m-%d %H:%M:%S")
git add content/daily-notes/
git commit -m "Obsidian Sync $current_datetime"
echo "Changes committed successfully."
else
echo "No changes to commit."
fi
14 changes: 14 additions & 0 deletions templates/shell.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{.Title}}</title>
</head>
<body>
{{.Body}}
<footer>
<p>© Deepak Jois</p>
</footer>
</body>
</html>
34 changes: 34 additions & 0 deletions upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# S3 bucket name
S3_BUCKET="debugjois-dev-site"

# local folder path
LOCAL_FOLDER="build"

# Loop through all files in the local folder
for file in "$LOCAL_FOLDER"/*; do
# Get the filename
filename=$(basename "$file")

# Get the file extension
extension="${filename##*.}"

# Set the content type
if [ "$extension" = "$filename" ]; then
# No extension, set MIME type to text/html
content_type="text/html"
else
# Use the default content type based on the file extension
content_type=""
fi

# Upload the file to S3
if [ -n "$content_type" ]; then
aws s3 cp "$file" "s3://$S3_BUCKET/$filename" --content-type "$content_type"
else
aws s3 cp "$file" "s3://$S3_BUCKET/$filename"
fi
done

echo "Upload complete!"

0 comments on commit ff4c52c

Please sign in to comment.