Closed rea1shane closed 3 months ago
Can you please split your PR to solve only the minifying?
I've the policy to have each issue managed with a unique PR. Do not hesitate to create an issue and other PRs for your color simplification proposition and other issues.
Also: please do not change the CSS or other things, just unminify it (for this PR).
Also: please do not change the CSS or other things, just unminify it (for this PR).
All right, see https://github.com/martignoni/hugo-notice/pull/37
Conflict resolved, please review and check it. @martignoni
Could you please explain why these simplifications?
Could you please explain why these simplifications?
This PR has made six modifications:
Since notice defaults to note
and is too similar to note
when the user sets noticeType
to something other than the preset (which, by the way, doesn't look right on the current main
branch in dark mode), note
and the non-preset values are set to the same color and are used as the base color for notice.
Previously, adding a new preset required modifying five places:
.notice {
--new-title: #5a5;
--new-content: #efe;
}
@media (prefers-color-scheme:dark) {
.notice {
--new-title: #363;
--new-content: #121;
}
}
body.dark .notice {
--new-title: #363;
--new-content: #121;
}
.notice.new .notice-title {
background: var(--new-title)
}
.notice.new {
background: var(--new-content)
}
now it only requires three:
.notice.new {
--title-background-color: #fb7;
--content-background-color: #fec;
}
@media (prefers-color-scheme:dark) {
.notice.new {
--title-background-color: #a50;
--content-background-color: #420;
}
}
body.dark .notice.new {
--title-background-color: #363;
--content-background-color: #121;
}
And it reads more clearly.
Change $.Page.Scratch.Add
to $.Page.Scratch.Set
. Because it's simpler and we just need a flag. This is Hugo's source code:
// Add will, for single values, add (using the + operator) the addend to the existing addend (if found).
// Supports numeric values and strings.
//
// If the first add for a key is an array or slice, then the next value(s) will be appended.
func (c *Scratch) Add(key string, newAddend any) (string, error) {
var newVal any
c.mu.RLock()
existingAddend, found := c.values[key]
c.mu.RUnlock()
if found {
var err error
addendV := reflect.TypeOf(existingAddend)
if addendV.Kind() == reflect.Slice || addendV.Kind() == reflect.Array {
newVal, err = collections.Append(existingAddend, newAddend)
if err != nil {
return "", err
}
} else {
newVal, err = math.DoArithmetic(existingAddend, newAddend, '+')
if err != nil {
return "", err
}
}
} else {
newVal = newAddend
}
c.mu.Lock()
c.values[key] = newVal
c.mu.Unlock()
return "", nil // have to return something to make it work with the Go templates
}
// Set stores a value with the given key in the Node context.
// This value can later be retrieved with Get.
func (c *Scratch) Set(key string, value any) string {
c.mu.Lock()
c.values[key] = value
c.mu.Unlock()
return ""
}
There is no need to operate style loaded flag every time when shortcode is called, just first time.
Remove first
class before notice-title
. It seems useless.
Added some missing ;
.
3. Change
$.Page.Scratch.Add
to$.Page.Scratch.Set
This needs its own PR (not related to color simplification).
5. Remove
first
class beforenotice-title
. It seems useless.
This too.
- Change
$.Page.Scratch.Add
to$.Page.Scratch.Set
This needs its own PR (not related to color simplification).
- Remove
first
class beforenotice-title
. It seems useless.This too.
I will do this tonight.
(…) which, by the way, doesn't look right on the current
main
branch in dark mode
Could you open an issue for that, since it looks like a bug?
(…) which, by the way, doesn't look right on the current
main
branch in dark modeCould you open an issue for that, since it looks like a bug?
Sure.
Fix #39
Seems no bug after update.
Light theme
Dark theme
Source code