]> sipb.mit.edu Git - ikiwiki.git/blob - doc/todo/calendar_autocreate.mdwn
explain why that default
[ikiwiki.git] / doc / todo / calendar_autocreate.mdwn
1 Here is a patch that makes [[ikiwiki-calendar]] almost useless.
2
3 It adds some options, the main one being `calendar_autocreate`, which is
4 similar to the `tag_autocreate` option of the [[tag|plugins/tag]]: it create
5 archive pages when needed.
6
7 The documentation is updated as well (but as a non-native English speaker, I
8 won't be offended if you correct stuff you consider awkward):
9
10 - [[plugin|https://github.com/paternal/ikiwiki/blob/calendar-autocreate/doc/plugins/calendar.mdwn]]
11 - [[directive|https://github.com/paternal/ikiwiki/blob/calendar-autocreate/doc/ikiwiki/directive/calendar.mdwn]]
12
13 [[!tag patch]]
14 [[!template  id=gitbranch branch=spalax/calendar-autocreate browse="https://github.com/paternal/ikiwiki/tree/calendar-autocreate" author="[[Louis|spalax]]"]]
15
16 --[[Louis|spalax]]
17
18 > An attempt at a review (although note that I don't have commit access,
19 > so my opinion is not final):
20 >
21 > Should `calendar_autocreate_commit` really default to 1? I would personally
22 > expect that any new features that synthesize new pages should not commit
23 > them by default - I'd prefer to avoid cluttering git history with generated
24 > pages. (Indeed, should the option even exist?)
25 >
26 > > I copied those options from the [[plugins/tag]] plugin: the
27 > > `tag_autocreate_commit` option exists and default to 1.
28 > >
29 > > It should definitely exists: suppose a calendar page is created and not
30 > > commited, and later, someone tries to push some changes where a page with
31 > > the same name has been created. This would result in a conflict. The
32 > > `calendar_autocreate_commit` prevents this.
33 >
34 > > > `tag_autocreate_commit` exists because when tag autocreation
35 > > > was introduced, they were always in the `$srcdir` and committed.
36 > > > I changed it so that it was possible to put them in the [[plugins/transient]]
37 > > > underlay and not commit them. It defaults to 1 to preserve existing
38 > > > functionality.
39 > > >
40 > > > When automatic tag pages (or autoindex pages) are not committed, they
41 > > > go in the transient underlay, which means they can't cause conflicts:
42 > > > independent page creation will simply mask them (a page in the
43 > > > `$srcdir` hides a page of the same name in an underlay). I thought
44 > > > this implementation did the same when not committing? --[[smcv]]
45 >
46 > I'd personally do the conditional in gencalendaryear more like:
47 >
48 > [[!format perl """
49 return unless $config{calendar_autocreate};
50 """]]
51 >
52 > to reduce the indentation depth of the more interesting code.
53 >
54 > > [[I agree|https://github.com/paternal/ikiwiki/commit/7f18c1ce48630507b744fa56b83999e8ca684606]]
55 >
56 > The recursion to generate missing years:
57 >
58 > [[!format perl """
59 if (not exists $wikistate{calendar}{minyear}) {
60         $wikistate{calendar}{minyear} = $year;
61 } elsif ($wikistate{calendar}{minyear} > $year) {
62         gencalendaryear($year + 1);
63         $wikistate{calendar}{minyear} -= 1;
64 }
65 """]]
66 >
67 > does seem to be correct on closer examination, but it took me a while
68 > to work out that it would actually do the right thing by recursing:
69 >
70 > * generate 2005
71 >   * recurse to generate 2006
72 >     * recurse to generate 2007
73 >       * recurse to generate 2008
74 >         * recurse to generate 2009
75 >           * recurse to try to generate 2010 (no effect)
76 >         * minyear = minyear - 1 = 2010 - 1 = 2009
77 >       * minyear = minyear - 1 = 2009 - 1 = 2008
78 >     * minyear = minyear - 1 = 2008 - 1 = 2007
79 >   * minyear = minyear - 1 = 2007 - 1 = 2006
80 > * minyear = minyear - 1 = 2006 - 1 = 2005
81 >
82 > I think it might be clearer (as well as less
83 > recursion-happy) to use iteration:
84 >
85 > * generate 2005
86 >   * recurse to generate 2006
87 >   * ...
88 >   * recurse to generate 2009
89 > * minyear = 2005
90 >
91 > something like this:
92 >
93 > [[!format perl """
94 sub gencalendaryear {
95         my $year = shift;
96         my %params = @_;
97         ...
98         # generate this year
99         ...
100         # Filling potential gaps in years [...] years 2006 to 2009.
101         return if $params{norecurse};
102         if (not exists $wikistate{calendar}{minyear}) {
103                 $wikistate{calendar}{minyear} = $year;
104         } elsif ($wikistate{calendar}{minyear} > $year) {
105                 foreach my $other ($year + 1 .. $wikistate{calendar}{minyear} - 1) {
106                         gencalendar($year, norecurse => 1);
107                 }
108                 $wikistate{calendar}{minyear} = $year;
109         }
110         # ... and the opposite for maxyear
111 }
112 """]]
113 >
114 >
115 > > [[I agree|https://github.com/paternal/ikiwiki/commit/7f18c1ce48630507b744fa56b83999e8ca684606]]
116 >
117 > I'm not sure about generating missing years at all, though: if the
118 > generation is entirely dynamic, and there were no posts at all during
119 > a particular year (or month for that matter), shouldn't we just skip
120 > the year/month? That seems to be what e.g. Wordpress does.
121 >
122 > > [[Done|https://github.com/paternal/ikiwiki/commit/59b46942e01b32138d056381249effbbaf773892]].
123 > > I added an option `calendar_fill_gaps` to chose between the two
124 > > alternatives (since skipping empty months and years would change the
125 > > default behaviour of this plugin).
126 > >
127 > > I think the code is a bit ugly at some places. Perl is not one the the
128 > > programming languages I am fluent into. Sorry.
129 > >
130 > > PS: Good idea, thought. I now have to implement a similar thing for
131 > > [[plugins/contrib/jscalendar]].
132 >
133 > This piece of ikiwiki-calendar functionality is lost:
134 >
135 > [[!format diff """
136 - ... It also refreshes the wiki, updating the calendars to
137 -highlight the current day. This command is typically run at midnight from
138 -cron.
139 """]]
140 >
141 > If I understand correctly, the highlight will be on the day at which
142 > the wiki was last refreshed, which seems arbitrary and confusing.
143 > If ikiwiki-calendar is not used, I'd say there should just not be a
144 > highlight for today (although I'm not sure how best to implement that -
145 > perhaps a config option representing "I am going to use ikiwiki-calendar").
146 >
147 > > This is not lost. What ikiwiki-calendar do is simply: build the missing
148 > > `archive/year/month` pages, and run `ikiwiki -refresh`. With my patch, the
149 > > `ikiwiki -refresh` includes:
150 > >
151 > > - the build of missing `archive/year/month` pages;
152 > > - highlighting the current day (this was already the case).
153 > >
154 > > So one can simply drop the `ikiwiki-calendar ...` for `ikiwiki --refresh
155 > > ...` in cron to get the same result.
156 > >
157 > > I
158 > > [[tried|https://github.com/paternal/ikiwiki/commit/7a92444e56fe023cea3b074dc5e6b5c4acdb6114]]
159 > > to make the documentation clearer.
160 >
161 > [[!format diff """
162 -\[[!template id=plugin name=calendar author="\[[ManojSrivastava]]"]]
163 -\[[!tag type/widget]]
164 """]]
165 >
166 > Why did you remove that? It's useful information about the plugin
167 > which I think ought to stay.
168 >
169 > > Oops! It was a mistake.
170 > > [[Corrected|https://github.com/paternal/ikiwiki/commit/de9842ecc8914e11e73148dae78cd6909b535262]].
171 >
172 > --[[smcv]]
173 >
174 > > Thank you for this review. -- [[Louis|spalax]]