Skip to content

Commit

Permalink
Merge branch 'sass'
Browse files Browse the repository at this point in the history
  • Loading branch information
movsb committed Dec 12, 2024
2 parents 70704e7 + 9a157f1 commit 614b37b
Show file tree
Hide file tree
Showing 27 changed files with 259 additions and 174 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: ./setup/scripts/run-in-docker.sh 'make tools && make protos generate test theme build'
- run: ./setup/scripts/run-in-docker.sh 'make tools protos generate test build'
- run: make build-image
- name: Login to Docker Hub
uses: docker/login-action@v1
Expand Down
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ RUN cd /katex && qjsc katex.min.js main.js

################################################################################

FROM alpine:3.20 AS sass
RUN wget -O sass.tgz 'https://github.com/sass/dart-sass/releases/download/1.82.0/dart-sass-1.82.0-linux-x64.tar.gz'
RUN mkdir -p /tmp/sass && tar xzvf sass.tgz -C /tmp/sass

################################################################################

FROM alpine:3.15
RUN apk add ca-certificates
RUN apk add sqlite
Expand All @@ -15,7 +21,9 @@ RUN apk add mailcap
RUN apk add exiftool

WORKDIR /workspace
COPY --from=katex /katex/a.out katex
COPY --from=katex /katex/a.out /usr/local/bin/katex
COPY --from=sass /tmp/sass/dart-sass /opt/sass
RUN cd /usr/local/bin && ln -s /opt/sass/sass

ADD taoblog /usr/local/bin/taoblog
ENTRYPOINT ["taoblog"]
Expand Down
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
protos:
./setup/scripts/build-protos.sh

.PHONY: theme
theme:
@cd theme/blog/styles && ./make_style.sh

.PHONY: test
test:
go test ./...
Expand Down
4 changes: 2 additions & 2 deletions admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"github.com/movsb/taoblog/modules/auth"
"github.com/movsb/taoblog/modules/utils"
"github.com/movsb/taoblog/modules/utils/dir"
"github.com/movsb/taoblog/modules/version"
co "github.com/movsb/taoblog/protocols/go/handy/content_options"
"github.com/movsb/taoblog/protocols/go/proto"
"github.com/movsb/taoblog/service"
"github.com/movsb/taoblog/theme/modules/handle304"
)

Expand Down Expand Up @@ -135,7 +135,7 @@ func (a *Admin) Handler() http.Handler {

func (a *Admin) cachedHandler(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if service.DevMode() {
if version.DevMode() {
handle304.MustRevalidate(w)
} else {
handle304.CacheShortly(w)
Expand Down
9 changes: 5 additions & 4 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/movsb/taoblog/modules/metrics/exporters/hostdare"
"github.com/movsb/taoblog/modules/notify"
"github.com/movsb/taoblog/modules/utils"
"github.com/movsb/taoblog/modules/version"
"github.com/movsb/taoblog/protocols/go/proto"
"github.com/movsb/taoblog/service"
"github.com/movsb/taoblog/service/models"
Expand Down Expand Up @@ -91,7 +92,7 @@ func (s *Server) Serve(ctx context.Context, testing bool, cfg *config.Config, re
log.Println(`加载配置:`, path)
})

log.Println(`DevMode:`, service.DevMode())
log.Println(`DevMode:`, version.DevMode())
log.Println(`Time.Now:`, time.Now().Format(time.RFC3339))

instantNotifier := notify.NewConsoleNotify()
Expand Down Expand Up @@ -122,7 +123,7 @@ func (s *Server) Serve(ctx context.Context, testing bool, cfg *config.Config, re
store = storage.NewLocal(cfg.Data.File.Path)
}

theAuth := auth.New(cfg.Auth, service.DevMode())
theAuth := auth.New(cfg.Auth, version.DevMode())
s.Auther = theAuth

serviceOptions := []service.With{
Expand All @@ -149,7 +150,7 @@ func (s *Server) Serve(ctx context.Context, testing bool, cfg *config.Config, re
panic(err)
}

a := admin.NewAdmin(service.DevMode(), theService, theAuth, prefix, u.Hostname(), cfg.Site.Name, []string{u.String()},
a := admin.NewAdmin(version.DevMode(), theService, theAuth, prefix, u.Hostname(), cfg.Site.Name, []string{u.String()},
admin.WithCustomThemes(&cfg.Theme),
)
log.Println(`admin on`, prefix)
Expand Down Expand Up @@ -179,7 +180,7 @@ func (s *Server) Serve(ctx context.Context, testing bool, cfg *config.Config, re
)
}

theme := theme.New(service.DevMode(), cfg, theService, theService, theService, theAuth, store)
theme := theme.New(version.DevMode(), cfg, theService, theService, theService, theAuth, store)
canon := canonical.New(theme, r)
mux.Handle(`/`, canon)

Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/grpc v1.59.0
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0
google.golang.org/protobuf v1.33.0
google.golang.org/protobuf v1.35.2
gopkg.in/yaml.v2 v2.4.0
)

Expand All @@ -44,6 +44,8 @@ require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/bep/godartsass/v2 v2.3.2 // indirect
github.com/cli/safeexec v1.0.1 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/dlclark/regexp2 v1.11.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bep/godartsass/v2 v2.3.2 h1:meuc76J1C1soSCAnlnJRdGqJ5S4m6/GW+8hmOe9tOog=
github.com/bep/godartsass/v2 v2.3.2/go.mod h1:Qe5WOS9nVJy7G0jHssXPd3c+Pqk/f7+Tm6k/vahbVgs=
github.com/bits-and-blooms/bitset v1.2.0 h1:Kn4yilvwNtMACtf1eYDlG8H77R07mZSPbMjLyS07ChA=
github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
github.com/blevesearch/go-porterstemmer v1.0.3 h1:GtmsqID0aZdCSNiY8SkuPJ12pD4jI+DdXTAn4YRcHCo=
Expand All @@ -69,6 +71,8 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cli/safeexec v1.0.1 h1:e/C79PbXF4yYTN/wauC4tviMxEV13BwljGj0N9j+N00=
github.com/cli/safeexec v1.0.1/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
Expand Down Expand Up @@ -523,6 +527,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
6 changes: 6 additions & 0 deletions modules/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package version
import (
"fmt"
"os"
"strings"
"time"

"github.com/spf13/cobra"
Expand All @@ -11,6 +12,11 @@ import (
// 运行起始时间。
var Time = time.Now()

// 是否是开发模式
func DevMode() bool {
return os.Getenv(`DEV`) != `0` && (GitCommit == "" || strings.EqualFold(GitCommit, `head`))
}

// 在编译脚本里面被注入进来。
var (
BuiltOn string
Expand Down
7 changes: 1 addition & 6 deletions service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"log"
"net"
"net/url"
"os"
"runtime"
"strings"
"sync"
Expand Down Expand Up @@ -268,7 +267,7 @@ func newService(ctx context.Context, cancel context.CancelFunc, cfg *config.Conf
log.Println(`GRPC listen on:`, listener.Addr().String())
go server.Serve(listener)

if !testing && !DevMode() {
if !testing && !version.DevMode() {
go s.monitorCert(s.instantNotifier)
go s.monitorDomain(s.instantNotifier)
}
Expand Down Expand Up @@ -374,10 +373,6 @@ func (s *Service) TxCall(callback func(txs *Service) error) error {
})
}

func DevMode() bool {
return os.Getenv(`DEV`) != `0` && (version.GitCommit == "" || strings.EqualFold(version.GitCommit, `head`))
}

// 是否在维护模式。
// 1. 手动进入。
// 2. 自动升级过程中。
Expand Down
1 change: 1 addition & 0 deletions service/modules/renderers/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style.css*
5 changes: 5 additions & 0 deletions service/modules/renderers/friends/friends.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ import (

"github.com/PuerkitoBio/goquery"
"github.com/movsb/taoblog/modules/utils"
"github.com/movsb/taoblog/modules/utils/dir"
dynamic "github.com/movsb/taoblog/service/modules/renderers/_dynamic"
"github.com/movsb/taoblog/theme/modules/sass"
"gopkg.in/yaml.v2"
)

//go:generate sass style.scss style.css

//go:embed friend.html style.css
var _root embed.FS

Expand All @@ -26,6 +30,7 @@ func init() {
string(utils.Must1(_root.ReadFile(`style.css`))),
},
}
sass.WatchDefaultAsync(string(dir.SourceRelativeDir()))
}

type Friends struct {
Expand Down
12 changes: 0 additions & 12 deletions service/modules/renderers/friends/style.css

This file was deleted.

56 changes: 56 additions & 0 deletions service/modules/renderers/friends/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
.friends {
display: flex;
flex-wrap: wrap;
gap: var(--border-radius);
.friend {
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
display: flex;
width: 278px;
.left {
width: 70px;
height: 70px;
min-width: 70px;
text-align: center;
align-self: center;
align-content: center;
margin: .5rem;
img {
max-width: 100% !important;
max-height: 100% !important;
width: 100%;
height: 100%;
object-fit: cover;
}
}
.right {
display: flex;
flex-direction: column;
align-self: center;
margin-right: .5rem;
p {
margin: 0;
&:not(:nth-child(1)) {
font-size: 80%;
}
}
}
}
}

/* <picture> 里面用 data-url 图片会不显示,找不到原因。
所以这里暂时用这种方式来切换日间/夜间显示。
https://blog.twofei.com/608/#comment-1792
*/
@media screen and (prefers-color-scheme: light) {
.friend {
.light { display: block; }
.dark { display: none; }
}
}
@media screen and (prefers-color-scheme: dark) {
.friend {
.light { display: none; }
.dark { display: block; }
}
}
2 changes: 0 additions & 2 deletions service/modules/renderers/highlight/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion service/modules/renderers/math/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func render(tex string, displayMode bool) (string, error) {
DisplayMode: displayMode,
}
body, _ := json.Marshal(args)
cmd := exec.Command(`./katex`)
cmd := exec.Command(`katex`)
cmd.Stdin = bytes.NewReader(body)
out, err := cmd.Output()
return string(out), err
Expand Down
3 changes: 2 additions & 1 deletion service/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
wikitable "github.com/movsb/goldmark-wiki-table"
"github.com/movsb/taoblog/modules/auth"
"github.com/movsb/taoblog/modules/utils"
"github.com/movsb/taoblog/modules/version"
co "github.com/movsb/taoblog/protocols/go/handy/content_options"
"github.com/movsb/taoblog/protocols/go/proto"
"github.com/movsb/taoblog/service/models"
Expand Down Expand Up @@ -263,7 +264,7 @@ func (s *Service) renderMarkdown(secure bool, postId, commentId int64, sourceTyp
}

var mediaTagOptions []media_tags.Option
if DevMode() {
if version.DevMode() {
mediaTagOptions = append(mediaTagOptions,
media_tags.WithDevMode(func() { s.themeChangedAt = time.Now() }),
)
Expand Down
2 changes: 1 addition & 1 deletion setup/build-tool/install-sass.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -eu

SASS_LINK='https://github.com/sass/dart-sass/releases/download/1.58.0/dart-sass-1.58.0-linux-x64.tar.gz'
SASS_LINK='https://github.com/sass/dart-sass/releases/download/1.82.0/dart-sass-1.82.0-linux-x64.tar.gz'
curl -Lo sass.tgz "$SASS_LINK"
mkdir -p /tmp/sass && tar xzvf sass.tgz -C /tmp/sass
ln -s /tmp/sass/dart-sass/sass /usr/local/bin
6 changes: 3 additions & 3 deletions theme/blog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ import (
//go:embed statics templates/*
var Root embed.FS

func SourceRelativeDir() dir.Dir {
return dir.SourceRelativeDir()
}
//go:generate sass --style compressed --no-source-map styles/style.scss statics/style.css

var SourceRelativeDir = dir.SourceRelativeDir()
40 changes: 0 additions & 40 deletions theme/blog/styles/content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -224,43 +224,3 @@ blockquote {
height: 100px !important;
}
}

.friends {
display: flex;
flex-wrap: wrap;
gap: var(--border-radius);
.friend {
border: 1px solid var(--border-color);
border-radius: var(--border-radius);
display: flex;
width: 278px;
.left {
width: 70px;
height: 70px;
min-width: 70px;
text-align: center;
align-self: center;
align-content: center;
margin: .5rem;
img {
max-width: 100% !important;
max-height: 100% !important;
width: 100%;
height: 100%;
object-fit: cover;
}
}
.right {
display: flex;
flex-direction: column;
align-self: center;
margin-right: .5rem;
p {
margin: 0;
&:not(:nth-child(1)) {
font-size: 80%;
}
}
}
}
}
Loading

0 comments on commit 614b37b

Please sign in to comment.