Compare commits

..

4 commits
v1 ... main

Author SHA1 Message Date
Magnus Åhall
f825acc8c0 Ironed out another december bug 2025-11-17 10:32:46 +01:00
Magnus Åhall
6cdb1c9bd8 Fixed december in calendar and modernized CSS 2025-11-06 19:38:03 +01:00
e08667ef11 Update README.md 2025-09-09 23:59:24 +02:00
30e3e5047a Add README.md 2025-09-09 23:58:13 +02:00
2 changed files with 104 additions and 78 deletions

View file

@ -11,15 +11,13 @@ function generate_calendar(calendarID, year, month)
-- A specified year and month will always display that calendar. -- A specified year and month will always display that calendar.
if year == 0 and month == 0 then if year == 0 and month == 0 then
local wantedMonth = clientStore.get("calendar:" .. calendarID) local wantedMonth = clientStore.get("calendar:" .. calendarID)
editor.flashNotification(wantedMonth)
-- Calculate year and month from the current date plus a month offset. -- Calculate year and month from the current date plus a month offset.
if wantedMonth == nil then if wantedMonth == nil then
wantedMonth = tonumber(os.date("%Y")) * 12 + tonumber(os.date("%m")) wantedMonth = tonumber(os.date("%Y")) * 12 + (tonumber(os.date("%m"))-1)
end end
year = (wantedMonth - (wantedMonth % 12)) / 12 year = (wantedMonth - (wantedMonth % 12)) / 12
month = wantedMonth % 12 month = wantedMonth % 12 + 1
if month == 0 then
month = 1
end
end end
local events = query[[ local events = query[[
@ -73,12 +71,12 @@ function generate_calendar(calendarID, year, month)
for _, e in pairs(events) do for _, e in pairs(events) do
local datematch = e.at.match( local datematch = e.at.match(
string.format("^%d-%02d-%02d( +[0-9]+:[0-9]+)?", year, month, day)) string.format("^%d-%02d-%02d( +[0-9]+:[0-9]+)?", year, month, day))
if #datematch >= 2 and not datematch[2] then if datematch and #datematch >= 2 and not datematch[2] then
cellcontent = cellcontent .. string.format( cellcontent = cellcontent .. string.format(
[[<a href="%s"><div class="event all-day">%s</div></a>]], [[<a href="%s"><div class="event all-day">%s</div></a>]],
e.ref, e.name e.ref, e.name
) )
elseif #datematch >= 2 and datematch[2] then elseif datematch and #datematch >= 2 and datematch[2] then
cellcontent = cellcontent .. string.format( cellcontent = cellcontent .. string.format(
[[ [[
<a href="%s"> <a href="%s">
@ -166,52 +164,49 @@ end
```space-style ```space-style
.calendartable { .calendartable {
border-collapse: collapse; border-collapse: collapse;
/* width: 500px; */
}
.calendartable table { table {
border-color: var(--panel-border-color); border-color: var(--panel-border-color);
border: 2px solid #444; border: 2px solid #444;
border-collapse: collapse; border-collapse: collapse;
}
.calendartable th { th {
width: 14%; width: 14%;
padding: 3px; padding: 3px;
text-align: left; text-align: left;
background-color: var(--panel-background-color); background-color: var(--panel-background-color);
color: #852624; color: #852624;
border: 1px solid #aaa; border: 1px solid #aaa;
} }
td {
.calendartable td {
width: 14%; width: 14%;
padding: 3px; padding: 3px;
text-align: left; text-align: left;
vertical-align: top; vertical-align: top;
border: 1px solid #aaa; border: 1px solid #aaa;
}
.calendartable td.today { &.today {
background-color: #f6f3c2; background-color: #f6f3c2;
} }
}
}
.calendartable a { a {
text-decoration-line: none; text-decoration-line: none;
color: var(--root-color); color: var(--root-color);
}
.calendartable a.mark { &.mark {
text-decoration-line: none; text-decoration-line: none;
color: var(--ui-accent-text-color); color: var(--ui-accent-text-color);
} }
}
.calendartable span.extramarker { span.extramarker {
background-color: yellow; background-color: yellow;
} }
.calendartable .event { .event {
background-color: #2ca05a; background-color: #2ca05a;
color: #fff; color: #fff;
border-radius: 4px; border-radius: 4px;
@ -221,20 +216,20 @@ end
white-space: normal; white-space: normal;
overflow-wrap: normal !important; overflow-wrap: normal !important;
word-break: normal !important; word-break: normal !important;
}
.calendartable .event.all-day { &.all-day {
background-color: #852624; background-color: #852624;
} }
.calendartable .event .time { .time {
font-weight: bold; font-weight: bold;
} }
}
.calendartable .month-prev, .month-prev,
.calendartable .month-next, .month-next,
.calendartable .month-now { .month-now {
cursor: pointer; cursor: pointer;
}
} }
``` ```

31
README.md Normal file
View file

@ -0,0 +1,31 @@
# Calendar
```lua
generate_calendar(idString, fixedYear, fixedMonth)
```
## Aktuell månad
Genererar en kalender med dagens datum, eller sparar senaste månaden med namnet "foo". Genereras en till kalender med samma namn visar den samma månad.
```lua
generate_calendar("foo", 0, 0)
```
## Specifik månad
För att visa en kalender med enbart september 2025:
```lua
generate_calendar("fixed:1", 2025, 9)
```
## Events
Events läggs till med:
```plaintext
* En text för eventet [at: 2025-09-10] #event
```
eller
```plaintext
* En text för eventet [at: 2025-09-10 08:00] #event
```