1 Here is a patch that makes [[ikiwiki-calendar]] almost useless.
3 > [[merged|done]], thanks! --[[smcv]]
5 It adds some options, the main one being `calendar_autocreate`, which is
6 similar to the `tag_autocreate` option of the [[tag|plugins/tag]]: it create
7 archive pages when needed.
9 The documentation is updated as well (but as a non-native English speaker, I
10 won't be offended if you correct stuff you consider awkward):
12 - [[plugin|https://github.com/paternal/ikiwiki/blob/calendar-autocreate/doc/plugins/calendar.mdwn]]
13 - [[directive|https://github.com/paternal/ikiwiki/blob/calendar-autocreate/doc/ikiwiki/directive/calendar.mdwn]]
16 [[!template id=gitbranch branch=spalax/calendar-autocreate browse="https://github.com/paternal/ikiwiki/tree/calendar-autocreate" author="[[Louis|spalax]]"]]
20 > An attempt at a review (although note that I don't have commit access,
21 > so my opinion is not final):
23 > Should `calendar_autocreate_commit` really default to 1? I would personally
24 > expect that any new features that synthesize new pages should not commit
25 > them by default - I'd prefer to avoid cluttering git history with generated
26 > pages. (Indeed, should the option even exist?)
28 > > I copied those options from the [[plugins/tag]] plugin: the
29 > > `tag_autocreate_commit` option exists and default to 1.
31 > > It should definitely exists: suppose a calendar page is created and not
32 > > commited, and later, someone tries to push some changes where a page with
33 > > the same name has been created. This would result in a conflict. The
34 > > `calendar_autocreate_commit` prevents this.
36 > > > `tag_autocreate_commit` exists because when tag autocreation
37 > > > was introduced, they were always in the `$srcdir` and committed.
38 > > > I changed it so that it was possible to put them in the [[plugins/transient]]
39 > > > underlay and not commit them. It defaults to 1 to preserve existing
42 > > > When automatic tag pages (or autoindex pages) are not committed, they
43 > > > go in the transient underlay, which means they can't cause conflicts:
44 > > > independent page creation will simply mask them (a page in the
45 > > > `$srcdir` hides a page of the same name in an underlay). I thought
46 > > > this implementation did the same when not committing? --[[smcv]]
48 > > > > I did not realize how easy it was to use the [[plugins/transient]]
49 > > > > plugin! I [[took it into
50 > > > > account|https://github.com/paternal/ikiwiki/commit/492a22ac75f8b41a427a98c44525b01a6fd181b5]].
51 > > > > -- [[Louis|spalax]]
53 > I'd personally do the conditional in gencalendaryear more like:
56 return unless $config{calendar_autocreate};
59 > to reduce the indentation depth of the more interesting code.
61 > > [[I agree|https://github.com/paternal/ikiwiki/commit/7f18c1ce48630507b744fa56b83999e8ca684606]]
63 > The recursion to generate missing years:
66 if (not exists $wikistate{calendar}{minyear}) {
67 $wikistate{calendar}{minyear} = $year;
68 } elsif ($wikistate{calendar}{minyear} > $year) {
69 gencalendaryear($year + 1);
70 $wikistate{calendar}{minyear} -= 1;
74 > does seem to be correct on closer examination, but it took me a while
75 > to work out that it would actually do the right thing by recursing:
78 > * recurse to generate 2006
79 > * recurse to generate 2007
80 > * recurse to generate 2008
81 > * recurse to generate 2009
82 > * recurse to try to generate 2010 (no effect)
83 > * minyear = minyear - 1 = 2010 - 1 = 2009
84 > * minyear = minyear - 1 = 2009 - 1 = 2008
85 > * minyear = minyear - 1 = 2008 - 1 = 2007
86 > * minyear = minyear - 1 = 2007 - 1 = 2006
87 > * minyear = minyear - 1 = 2006 - 1 = 2005
89 > I think it might be clearer (as well as less
90 > recursion-happy) to use iteration:
93 > * recurse to generate 2006
95 > * recurse to generate 2009
98 > something like this:
101 sub gencalendaryear {
107 # Filling potential gaps in years [...] years 2006 to 2009.
108 return if $params{norecurse};
109 if (not exists $wikistate{calendar}{minyear}) {
110 $wikistate{calendar}{minyear} = $year;
111 } elsif ($wikistate{calendar}{minyear} > $year) {
112 foreach my $other ($year + 1 .. $wikistate{calendar}{minyear} - 1) {
113 gencalendar($year, norecurse => 1);
115 $wikistate{calendar}{minyear} = $year;
117 # ... and the opposite for maxyear
122 > > [[I agree|https://github.com/paternal/ikiwiki/commit/7f18c1ce48630507b744fa56b83999e8ca684606]]
124 > I'm not sure about generating missing years at all, though: if the
125 > generation is entirely dynamic, and there were no posts at all during
126 > a particular year (or month for that matter), shouldn't we just skip
127 > the year/month? That seems to be what e.g. Wordpress does.
129 > > [[Done|https://github.com/paternal/ikiwiki/commit/59b46942e01b32138d056381249effbbaf773892]].
130 > > I added an option `calendar_fill_gaps` to chose between the two
131 > > alternatives (since skipping empty months and years would change the
132 > > default behaviour of this plugin).
134 > > I think the code is a bit ugly at some places. Perl is not one the the
135 > > programming languages I am fluent into. Sorry.
137 > > PS: Good idea, thought. I now have to implement a similar thing for
138 > > [[plugins/contrib/jscalendar]].
140 > This piece of ikiwiki-calendar functionality is lost:
143 - ... It also refreshes the wiki, updating the calendars to
144 -highlight the current day. This command is typically run at midnight from
148 > If I understand correctly, the highlight will be on the day at which
149 > the wiki was last refreshed, which seems arbitrary and confusing.
150 > If ikiwiki-calendar is not used, I'd say there should just not be a
151 > highlight for today (although I'm not sure how best to implement that -
152 > perhaps a config option representing "I am going to use ikiwiki-calendar").
154 > > This is not lost. What ikiwiki-calendar do is simply: build the missing
155 > > `archive/year/month` pages, and run `ikiwiki -refresh`. With my patch, the
156 > > `ikiwiki -refresh` includes:
158 > > - the build of missing `archive/year/month` pages;
159 > > - highlighting the current day (this was already the case).
161 > > So one can simply drop the `ikiwiki-calendar ...` for `ikiwiki --refresh
162 > > ...` in cron to get the same result.
165 > > [[tried|https://github.com/paternal/ikiwiki/commit/7a92444e56fe023cea3b074dc5e6b5c4acdb6114]]
166 > > to make the documentation clearer.
169 -\[[!template id=plugin name=calendar author="\[[ManojSrivastava]]"]]
170 -\[[!tag type/widget]]
173 > Why did you remove that? It's useful information about the plugin
174 > which I think ought to stay.
176 > > Oops! It was a mistake.
177 > > [[Corrected|https://github.com/paternal/ikiwiki/commit/de9842ecc8914e11e73148dae78cd6909b535262]].
181 > > Thank you for this review. -- [[Louis|spalax]]
185 [[smcv]], can you please go on reviewing this?
187 > I don't think I'm really the reviewer you want, since I don't have commit
188 > access (as you might be able to tell from the number of pending branches
189 > I have)... but nobody with commit access seems to be available to do
190 > reviews at the moment, so I'm probably the best you're going to get.
192 > + 0 0 * * * ikiwiki ~/ikiwiki.setup --refresh
194 > I think that should be `ikiwiki --setup ~/ikiwiki.setup --refresh`
196 > > [[Corrected|https://github.com/paternal/ikiwiki/commit/213dad76d47bab9db8e44d6e20c8371960375e77]]
198 > The indentation of some of the new code in `IkiWiki/Plugin/calendar.pm`
199 > is weird. Please use one hard tab (U+0009) per indent step: you seem
200 > to have used a mixture of one hard tab per indent or two spaces
201 > per indent, which looks bizarre for anyone whose tab size is not
204 > > [[Corrected|https://github.com/paternal/ikiwiki/commit/1d97160dae775c31e166d9886472dacdd773d571]]
206 > + return unless $config{calendar_autocreate};
208 > This is checked in `gencalendaryear` but not in `gencalendarmonth`.
209 > Shouldn't `gencalendarmonth` do it too? Alternatively, do the check
210 > in `scan`, which calls `gencalendarmonth` directly.
212 > > Once again, [[you are right|https://github.com/paternal/ikiwiki/commit/473bcbe7a42a4168cab82ed12185817248de045f]]
214 > + my $year = $date[5] + 1900;
216 > You calculate this, but you don't seem to do anything with it?
218 > > [[Corrected|https://github.com/paternal/ikiwiki/commit/d0b34951240317642543351ec62f98d3d8df8c0f]]
220 > + if (not exists $changed{$params{year}}) {
221 > + $changed{$params{year}} = ();
223 > + $changed{$params{year}}{$params{month}} = 1;
225 > `$changed{$params{year}}` is a scalar (you can tell because it starts with the
226 > `$` sigil) but `()` is a list. I think you want `{}`
227 > (a scalar that is a reference to an empty anonymous hash).
229 > However, that whole `if` block can be omitted, and you can just use
230 > `$changed{$params{year}}{$params{month}} = 1;`, because Perl will automatically
231 > create `$changed{$params{year}}` as a reference to an empty hash if necessary,
232 > in order to put the pair `$params{month} => 1` in it (the term to look
233 > up if you're curious is "autovivification").
235 > > [[Corrected|https://github.com/paternal/ikiwiki/commit/d0b34951240317642543351ec62f98d3d8df8c0f]]
239 > > Thank you for your review.
240 > > --[[Louis|spalax]]