Skip to content

Commit 3f29c8d

Browse files
authored
Merge pull request #290 from tmillr/fix-compile-all-themes
fix(compiler): compile all themes inst of 1 mult times
2 parents 067cb69 + 99d3b16 commit 3f29c8d

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

CHANGELOG.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020

2121
### Issues Fix
2222

23-
- Fixed few regex-based/legacy highlight corrections (fixed #285)
24-
- Closed #251
25-
- Fixed darkened sidebars when disabling `options.sidebars.disabled`
26-
- Fixes #311
23+
- Fixed few regex-based/legacy highlight corrections (fixed #285)
24+
- Closed #251
25+
- Fixed bug where the current theme gets compiled multiple times instead of compiling all themes #290
26+
- Fixed darkened sidebars when disabling `options.sidebars.disabled`
27+
- Fixes #311
2728

2829
## [v1.0.1] - 23 July 2023
2930

lua/github-theme/config.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ function M.reset()
9999
end
100100

101101
function M.get_compiled_info(opts)
102+
opts = opts or {}
102103
local output_path = opts.output_path or M.options.compile_path
103104
local file_suffix = opts.file_suffix or M.options.compile_file_suffix
104-
local style = opts.name or M.theme
105-
return output_path, util.join_paths(output_path, style .. file_suffix)
105+
return output_path, util.join_paths(output_path, (opts.theme or M.theme) .. file_suffix)
106106
end
107107

108108
function M.hash()

lua/github-theme/init.lua

+9-3
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,20 @@ function M.reset()
2424
require('github-theme.override').reset()
2525
end
2626

27+
---Compiles all themes/styles with their current settings.
28+
---@return nil
2729
function M.compile()
2830
require('github-theme.lib.log').clear()
29-
3031
local compiler = require('github-theme.lib.compiler')
3132
local themes = require('github-theme.palette').themes
32-
for _, style in ipairs(themes) do
33-
compiler.compile({ style = style })
33+
local current_theme = config.theme
34+
for _, theme in ipairs(themes) do
35+
-- Compile current theme last (see discussion in #290)
36+
if theme ~= current_theme then
37+
compiler.compile({ theme = theme })
38+
end
3439
end
40+
compiler.compile({ theme = current_theme })
3541
end
3642

3743
-- Avoid g:colors_name reloading

lua/github-theme/lib/compiler.lua

+8-5
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ local function should_link(link)
2222
return link and link ~= ''
2323
end
2424

25+
---Compiles a single theme/style. `opts.theme` specifies the theme to compile,
26+
---otherwise the currently-set theme will be compiled.
27+
---@param opts? { theme: string }
28+
---@return nil
2529
function M.compile(opts)
2630
opts = opts or {}
27-
local theme = config.theme
28-
local spec = require('github-theme.spec').load(theme)
31+
opts.theme = opts.theme or config.theme
32+
local spec = require('github-theme.spec').load(opts.theme)
2933
local groups = require('github-theme.group').from(spec)
3034
local background = spec.palette.meta.light and 'light' or 'dark'
3135

@@ -39,7 +43,7 @@ vim.o.termguicolors = true
3943
vim.g.colors_name = "%s"
4044
vim.o.background = "%s"
4145
]],
42-
theme,
46+
opts.theme,
4347
background
4448
),
4549
}
@@ -68,8 +72,6 @@ vim.o.background = "%s"
6872
end
6973

7074
table.insert(lines, 'end)')
71-
72-
opts.name = theme
7375
local output_path, output_file = config.get_compiled_info(opts)
7476
util.ensure_dir(output_path)
7577

@@ -97,6 +99,7 @@ Bellow is the error message:
9799
tmpfile
98100
)
99101
)
102+
100103
local efile = io.open(tmpfile, 'wb')
101104
efile:write(table.concat(lines, '\n'))
102105
efile:close()

0 commit comments

Comments
 (0)