Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: build css from less files locally #735

Merged
merged 17 commits into from Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/_styles-check.yml
@@ -0,0 +1,18 @@
name: "styles-check"

on: workflow_call

jobs:
styles-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f # v3.4.0

- name: Setup Bun
uses: oven-sh/setup-bun@a1800f471a0bc25cddac36bb13e6f436ddf341d7 # v1
with:
bun-version: "1.0.1"

- name: Check
run: make styles-check

4 changes: 3 additions & 1 deletion .github/workflows/pull_request.yml
Expand Up @@ -16,8 +16,10 @@ jobs:
uses: ./.github/workflows/_test.yml
call-swagger-check:
uses: ./.github/workflows/_swagger-check.yml
call-styles-check:
uses: ./.github/workflows/_styles-check.yml
call-gorelease:
needs: [call-lint, call-test, call-swagger-check]
needs: [call-lint, call-test, call-swagger-check, call-styles-check]
uses: ./.github/workflows/_gorelease.yml
call-buildx:
needs: call-gorelease
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -19,3 +19,6 @@ dist/

# macOS trash files
.DS_Store

# frontend
node_modules
13 changes: 13 additions & 0 deletions Makefile
Expand Up @@ -23,6 +23,9 @@ SHIORI_DEVELOPMENT ?= true
SWAG_VERSION := $(shell grep "swaggo/swag" go.mod | cut -d " " -f 2)
SWAGGER_DOCS_PATH ?= ./docs/swagger

# Frontend
CLEANCSS_OPTS ?= --with-rebase

# Help documentatin à la https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help
help:
Expand Down Expand Up @@ -71,6 +74,16 @@ golangci-lint:
unittest:
GIN_MODE=$(GIN_MODE) GO_TEST_FLAGS="$(GO_TEST_FLAGS)" GOTESTFMT_FLAGS="$(GOTESTFMT_FLAGS)" $(BASH) -xe ./scripts/test.sh

## Build styles
.PHONY: styles
styles:
CLEANCSS_OPTS=$(CLEANCSS_OPTS) $(BASH) ./scripts/styles.sh

## Build styles
.PHONY: styles-check
styles-check:
CLEANCSS_OPTS=$(CLEANCSS_OPTS) $(BASH) ./scripts/styles_check.sh

## Build binary
.PHONY: build
build: clean
Expand Down
Binary file added bun.lockb
Binary file not shown.
14 changes: 14 additions & 0 deletions docs/Contribute.md
Expand Up @@ -33,6 +33,20 @@ Then, run the following command:
make swagger
```

## Updating the frontend styles

The styles that are bundled with Shiori are stored under `internal/view/assets/css/style.css` and `internal/view/assets/css/archive.css` and created from the less files under `internal/views/assets/less`.

If you want to make frontend changes you need to do that under the less files and then compile them to css. In order to do that, you need to have installed [bun](https://bun.sh) (preferred) or [lessc](http://lesscss.org/usage/#command-line-usage)/[clean-css-cli](https://github.com/clean-css/clean-css-cli).

Then, run the following command:

```bash
make styles
```

The `style.css`/`archive.css` will be updated and changes **needs to be commited** to the repository.

## Lint the code

In order to lint the code, you need to have installed [golangci-lint](https://golangci-lint.run) and [swag](https://github.com/swaggo/swag).
Expand Down
4 changes: 2 additions & 2 deletions internal/http/routes/frontend_test.go
Expand Up @@ -35,9 +35,9 @@ func TestFrontendRoutes(t *testing.T) {
require.Equal(t, 200, w.Code)
})

t.Run("/css/stylesheet.css", func(t *testing.T) {
t.Run("/css/style.css", func(t *testing.T) {
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/assets/css/stylesheet.css", nil)
req, _ := http.NewRequest("GET", "/assets/css/style.css", nil)
g.ServeHTTP(w, req)
require.Equal(t, 200, w.Code)
})
Expand Down
1 change: 1 addition & 0 deletions internal/view/404.html
Expand Up @@ -4,6 +4,7 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="assets/css/style.css" rel="stylesheet">
<title>Shiori</title>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion internal/view/assets/css/archive.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion internal/view/assets/css/bookmark-item.css

This file was deleted.

1 change: 0 additions & 1 deletion internal/view/assets/css/custom-dialog.css

This file was deleted.

27 changes: 27 additions & 0 deletions internal/view/assets/css/libs/source-sans-pro.min.css
@@ -0,0 +1,27 @@
@font-face {
font-family: 'Source Sans Pro';
font-style: normal;
font-weight: 200;
src: local('Source Sans Pro ExtraLight'), local('SourceSansPro-ExtraLight'), url(fonts/source-sans-pro-v13-latin-200.woff2) format('woff2'), url(fonts/source-sans-pro-v13-latin-200.woff) format('woff')
}

@font-face {
font-family: 'Source Sans Pro';
font-style: normal;
font-weight: 400;
src: local('Source Sans Pro Regular'), local('SourceSansPro-Regular'), url(fonts/source-sans-pro-v13-latin-regular.woff2) format('woff2'), url(fonts/source-sans-pro-v13-latin-regular.woff) format('woff')
}

@font-face {
font-family: 'Source Sans Pro';
font-style: normal;
font-weight: 600;
src: local('Source Sans Pro SemiBold'), local('SourceSansPro-SemiBold'), url(fonts/source-sans-pro-v13-latin-600.woff2) format('woff2'), url(fonts/source-sans-pro-v13-latin-600.woff) format('woff')
}

@font-face {
font-family: 'Source Sans Pro';
font-style: normal;
font-weight: 700;
src: local('Source Sans Pro Bold'), local('SourceSansPro-Bold'), url(fonts/source-sans-pro-v13-latin-700.woff2) format('woff2'), url(fonts/source-sans-pro-v13-latin-700.woff) format('woff')
}
1 change: 0 additions & 1 deletion internal/view/assets/css/source-sans-pro.min.css

This file was deleted.

1 change: 1 addition & 0 deletions internal/view/assets/css/style.css

Large diffs are not rendered by default.