review and thoughts
[ikiwiki] / doc / todo / transient_pages.mdwn
1 On [[todo/auto-create_tag_pages_according_to_a_template]], [[chrysn]]
2 suggests:
3
4 > Instead of creating a file that gets checked in into the RCS, the
5 > source files could be left out and the output files be written as
6 > long as there is no physical source file (think of a virtual underlay).
7 > Something similar would be required to implement alias directive,
8 > which couldn't be easily done by writing to the RCS as the page's
9 > contents can change depending on which other pages claim it as an alias.
10
11 `add_autofile` could be adapted to do this, or a similar API could be
12 added.
13
14 This would also be useful for autoindex, as suggested on
15 [[plugins/autoindex/discussion]]. I'd also like to use it for
16 [[plugins/contrib/album]].
17
18 One refinement I'd suggest is that if the transient page is edited,
19 its transient contents are evaluated and used as the initial
20 content for the edit box; after that, it'd become a static page. --[[smcv]]
21
22 --------------------------
23
24 [[!template id=gitbranch branch=smcv/ready/transient author="[[smcv]]"]]
25 [[!tag patch]]
26
27 I think this branch is now enough to be useful. It adds the following:
28
29 If the `transient` plugin is loaded, `$srcdir/.ikiwiki/transient` is added
30 as an underlay. I'm not sure whether this should be a plugin or core, so
31 I erred on the side of more plugins; I think it's "on the edge of the core",
32 like goto.
33
34 Pages with the default extension in the transient underlay are automatically
35 deleted if a page of the same name is created in the srcdir (or an underlay
36 closer to the srcdir in stacking order).
37
38 `tag` enables `transient`, and if `tag_autocreate_commit` is set to 0
39 (default 1), autocreated tags are written to the transient underlay.
40 There is a regression test.
41
42 `autoindex` uses autofiles. It also enables `transient`, and if
43 `autoindex_commit` is set to 0 (default 1), autoindexes are written to
44 the transient underlay. There is a regression test.
45
46 > I wonder why this needs to be configurable? I suppose that gets back to
47 > whether it makes sense to check these files in or not. The benefits of 
48 > checking them in:
49
50 > * You can edit them from the VCS, don't have to go into the web
51 >   interface. Of course, files from the underlays have a similar issue,
52 >   but does it make sense to make that wart larger?
53 > * You can know you can build the same site with nothing missing
54 >   even if you don't there enable autoindex or whatever. (Edge case.)
55
56 > The benefit of using transient pages seems to just be avoiding commit
57 > clutter? For files that are never committed, transient pages are a clear
58 > win, but I wonder if adding configuration clutter just to avoid some 
59 > commit clutter is really worth it.
60
61 > Anyway, the configurability
62 > appears subtly broken; the default is only 1 if a new setup file is
63 > generated. With an existing setup file, the 'default' values in
64 > `getsetup` don't take effect, so it will default to undef, which
65 > is treated the same as 0. --[[Joey]]
66
67 autoindex ignores pages in the transient underlay when deciding whether
68 to generate an index.
69
70 New recent changes go in the transient underlay; I tested this manually.
71
72 Not done yet (in that branch, at least):
73
74 * `remove` can't remove transient pages: this turns out to be harder than
75   I'd hoped, because I don't want to introduce a vulnerability in the
76   non-regular-file detection, so I'd rather defer that.
77
78   > Hmm, I'd at least want that to be dealt with before this was used
79   > by default for autoindex or tag. --[[Joey]]
80
81 * Transient tags that don't match any pages aren't deleted: I'm not sure
82   that that's a good idea anyway, though. Similarly, transient autoindexes
83   of directories that become empty aren't deleted.
84
85   > Doesn't seem necessary, or really desirable to do that. --[[Joey]]
86
87 * In my `untested/transient` branch, new aggregated files go in the
88   transient underlay too (they'll naturally migrate over time). I haven't
89   tested this yet, it's just a proof-of-concept.
90
91 > I can confirm that the behavior of autoindex, at least, is excellent.
92 > Haven't tried tag. Joey, can you merge transient and autoindex? --JoeRayhawk
93
94 >> Here are some other things I'd like to think about first: --[[Joey]] 
95 >>
96 >> * There's a FIXME in autoindex.
97 >> * Suggest making recentchanges unlink the transient page
98 >>   first, and only unlink from the old location if it wasn't
99 >>   in the transient location. Ok, it only saves 1 syscall :)
100 >> * Similarly it's a bit worrying for performance that it
101 >>   needs to pull in and use `Cwd` on every ikiwiki startup now.
102 >>   I really don't see the need; `wikistatedir` should
103 >>   mostly be absolute, and ikiwiki should not chdir in ways
104 >>   that break it anyway.
105 >> * Unsure about the use of `default_pageext` in the `change`
106 >>   hook. Is everything in the transientdir really going
107 >>   to use that pageext? Would it be better to look up the
108 >>   complete source filename?
109
110 --------------------------
111
112 ## An earlier version
113
114 I had a look at implementing this. It turns out to be harder than I thought
115 to have purely in-memory pages (several plugins want to be able to access the
116 source file as a file), but I did get this proof-of-concept branch
117 to write tag and autoindex pages into an underlay.
118
119 This loses the ability to delete the auto-created pages (although they don't
120 clutter up git this way, at least), and a lot of the code in autoindex is
121 probably now redundant, so this is probably not quite ready for merge, but
122 I'd welcome opinions.
123
124 Usage: set `tag_underlay` and/or `autoindex_underlay` to an absolute path,
125 which you must create beforehand. I suggest *srcdir* + `/.ikiwiki/transient`.
126
127 Refinements that could be made if this approach seems reasonable:
128
129 * make these options boolean, and have the path always be `.ikiwiki/transient`
130 * improve the `remove` plugin so it also deletes from this special underlay
131
132 >> Perhaps it should be something more generic, so that other plugins could use it (such as "album" mentioned above).
133 >> The `.ikiwiki/transient` would suit this, but instead of saying "tag_underlay" or "autoindex_underlay" have "use_transient_underlay" or something like that?
134 >> Or to make it more flexible, have just one option "transient_underlay" which is set to an absolute path, and if it is set, then one is using a transient-underlay.
135 >> --[[KathrynAndersen]]
136
137 >>> What I had in mind was more like `tag_autocreate_transient => 1` or
138 >>> `autoindex_transient => 1`; you might conceivably want tags to be
139 >>> checked in but autoindices to be transient, and it's fine for each
140 >>> plugin to make its own decision. Going from that to one boolean
141 >>> (or just always-transient if people don't think that's too
142 >>> astonishing) would be trivial, though.
143 >>>
144 >>> I don't think relocating the transient underlay really makes sense,
145 >>> except for prototyping: you only want one, and `.ikiwiki` is as good
146 >>> a place as any (ikiwiki already needs to be able to write there).
147 >>>
148 >>> For [[plugins/contrib/album]] I think I'd just make the photo viewer
149 >>> pages always-transient - you can always make a transient page
150 >>> permanent by editing it, after all.
151 >>>
152 >>> Do you think this approach has enough potential that I should
153 >>> continue to hack on it? Any thoughts on the implementation? --[[smcv]]
154
155 >>>> Ah, now I understand what you're getting at. Yes, it makes sense to put transient pages under `.ikiwiki`.
156 >>>> I haven't looked at the code, but I'd be interested in seeing whether it's generic enough to be used by other plugins (such as `album`) without too much fuss.
157 >>>> The idea of a transient underlay gives us a desirable feature for free: that if someone edits the transient page, it is made permanent and added to the repository.
158 >>>>
159 >>>> I think the tricky thing with removing these transient underlay pages is the question of how to prevent whatever auto-generated the pages in the first place from generating them again - or, conversely, how to force whatever auto-generated those pages to regenerate them if you've changed your mind.
160 >>>> I think you'd need something similar to `will_render` so that transient pages would be automatically removed if whatever auto-generated them is no longer around.
161 >>>> -- [[KathrynAndersen]]