Paulo Almeida
2009-Oct-23 22:21 UTC
[webgen-users] webgen, include files and "static-changing" pages
Hi webgen users, I am using the tool for some weeks and now I am trying to maximize content reuse. I have a block of content (called "announce") which should be rendered in my leftside bar, for SOME of my pages. So I created a file called "announces.inc" in my root website folder and tried to conditionally call it, inside default.template, like the following code: <% if context.node.node_info[:page].blocks.has_key?(''announce'') %> <div id="announce"> <webgen:block name="announce" /> {include_file: news.inc} </div> <% end %> The condition works fine, selecting the appropriatte files to include the content, but the content itself is not well formatted as expected. Instead of using CSS properties defined to "announce" class, the raw "markdown" tags are presented in the output files, exact like this: ### News: **09/set/2009:** New version of home-page, using *webgen*. [Read more...](noticia001.html) ### Comments: [Place a comment about my page...](comments.html#disqus_thread) What am I doing wrong here? Another problem I have is that I want to create a page with some news. The headlines should appear at the main body of a "first news page" (FNP), with links to each complete article. Each article is a file newsXXX.page (newsXXX.html after webgen) and those headlines in the FNP should be ordered by date. Each time I put a new file on this folder, I will recompile the code and I would like it to have the headlines updated in the FNP. Is this possible? Thx 4 your attention and help, Paulo
Damien Pollet
2009-Oct-24 13:37 UTC
[webgen-users] webgen, include files and "static-changing" pages
On Sat, Oct 24, 2009 at 00:21, Paulo Almeida <pema at dri.cefetmg.br> wrote:> ?The condition works fine, selecting the appropriatte files to include > the content, but the content itself is not well formatted as expected. > Instead of using CSS properties defined to "announce" class, the raw > "markdown" tags are presented in the output files, exact like this:Did you try to set the process_output argument to include_file? http://webgen.rubyforge.org/documentation/tag/includefile.html> the FNP should be ordered by date. Each time I put a new file on this > folder, I will recompile the code and I would like it to have the > headlines updated in the FNP. Is this possible?No idea there, but I want to do basically the same, so I''m interested in anything you find :) -- Damien Pollet type less, do more [ | ] http://people.untyped.org/damien.pollet
Thomas Leitner
2009-Oct-24 17:46 UTC
[webgen-users] webgen, include files and "static-changing" pages
> I am using the tool for some weeks and now I am trying to maximize > content reuse. I have a block of content (called "announce") which > should be rendered in my leftside bar, for SOME of my pages. So I > created a file called "announces.inc" in my root website folder and > tried to conditionally call it, inside default.template, like the > following code: > > <SNIP /> > <webgen:block name="announce" /> > {include_file: news.inc} > <SNIP />Okay, I think what you want. You should do the following: create a file called "announces.page" (not .inc) and set the meta information `no_output: true` (then the page itself does not get rendered into an output file). After that you use the following instead of the `include_file` tag: <webgen:block name="content" chain="announces.html" /> This renders the content of the announces.page according to *its processing pipeline* and not according to the processing of the default.template which is what you probably want.> Another problem I have is that I want to create a page with some news. > The headlines should appear at the main body of a "first news > page" (FNP), with links to each complete article. Each article is a > file newsXXX.page (newsXXX.html after webgen) and those headlines in > the FNP should be ordered by date. Each time I put a new file on this > folder, I will recompile the code and I would like it to have the > headlines updated in the FNP. Is this possible?Certainly, yes. You would need some ERB to do this, something like the following in your FNP file: <% context.content_node.tree.node_access[:alcn].select do |alcn,no| alcn =~ /\/news.*\.html/ && no.is_file? end.collect {|na,no| no}.sort do |a,b| a[''sort_date''] <=> b[''sort_date''] end.reverse.each do |node| %> <h1><%= node.title %></h1> Published on <%= node[''created_at''].strftime("%A, %d %B %Y") %> - <%= context.dest_node.link_to(node, :link_text => "More information...") %> <% end %> The second line selects the nodes by matching the ALCN to a pattern (in this case, all files like /news*.html). The fourth line sorts the files by the meta information `sort_date` which has to be set by all files (you can use any other meta information key). The body just puts the title of the news page in an H1 header and puts a link to the page below. Best regards, Thomas
Paulo Almeida
2009-Oct-26 22:16 UTC
[webgen-users] webgen, include files and "static-changing" pages
Thank you very much, Thomas!!! I tried your suggestions and almost everything I needed is running fine right now. I will comment out some details in the lines below, to keep the forum well documented... On Oct 24, 3:46?pm, Thomas Leitner <t_leit... at gmx.at> wrote:> (...) > Okay, I think what you want. You should do the following: create a file > called "announces.page" (not .inc) and set the meta information > `no_output: true` (then the page itself does not get rendered into an > output file). After that you use the following instead of the > `include_file` tag: > > ? ? <webgen:block name="content" chain="announces.html" /> > > This renders the content of the announces.page according to *its > processing pipeline* and not according to the processing of the > default.template which is what you probably want.Works like a charm, as I needed!!! ;)> > Another problem I have is that I want to create a page with some news. > > The headlines should appear at the main body of a "first news > > page" (FNP), with links to each complete article. Each article is a > > file newsXXX.page (newsXXX.html after webgen) and those headlines in > > the FNP should be ordered by date. Each time I put a new file on this > > folder, I will recompile the code and I would like it to have the > > headlines updated in the FNP. Is this possible? > > Certainly, yes. You would need some ERB to do this, something like the > following in your FNP file: > > <% > context.content_node.tree.node_access[:alcn].select do |alcn,no| > ? alcn =~ /\/news.*\.html/ && no.is_file? > end.collect {|na,no| no}.sort do |a,b| > ? a[''sort_date''] <=> b[''sort_date''] > end.reverse.each do |node| > %> > <h1><%= node.title %></h1> > Published on <%= node[''created_at''].strftime("%A, %d %B %Y") %> - > <%= context.dest_node.link_to(node, :link_text => "More information...") %> > <% end %> > The second line selects the nodes by matching the ALCN to a pattern (in > this case, all files like /news*.html). The fourth line sorts the files > by the meta information `sort_date` which has to be set by all files > (you can use any other meta information key). The body just puts the > title of the news page in an H1 header and puts a link to the page > below.Ok, again it works, with some minor problems and corrections: 1. Instead of >>> <h1><%= node.title %></h1> I am using >>> <h1><%= node[''routed_title''] %></h1> 2. One problem I could not solve yet is the next line: >>> Published on <%= node[''created_at''].strftime("%A, %d %B %Y") %> - I keep getting error messages saying that some "nil" class doesn''t know the strftime method. But I can live without this. 3. Another one is as follows: my FNP includes, on top of actual headlines from my news, a "fake" headline containing title of the index.html page on my "news" folder. I tried using "in_menu: false" and "no_output: true", but without success as of now. In summary, if I have N news in the folder, I get N+1 headlines in my FNP, and the first one is a fake news corresponding to the index page. As I am not initiated with Ruby, for now, I could not fix this. Any ideas? Thx again for your help. Paulo
Thomas Leitner
2009-Oct-27 11:44 UTC
[webgen-users] webgen, include files and "static-changing" pages
> Ok, again it works, with some minor problems and corrections: > 1. Instead of > >>> <h1><%= node.title %></h1> > > I am using > >>> <h1><%= node[''routed_title''] %></h1>That''s okay but `routed_title` is normally only defined for directory index files. So you might want to use something like <h1><%= node[''routed_title''] || node[''title''] %></h1> And `node.title` naturally doesn''t work ;-) My fault, sorry!> 2. One problem I could not solve yet is the next line: > >>> Published on <%= node[''created_at''].strftime("%A, %d %B > %Y") %> - > > I keep getting error messages saying that some "nil" class > doesn''t know the > strftime method. But I can live without this.Try using the meta information `modified_at` instead of `created_at`. The former is available on all nodes while the latter has to be set individually since it cannot be derived.> 3. Another one is as follows: my FNP includes, on top of actual > headlines from my news, a "fake" > headline containing title of the index.html page on my "news" > folder. I tried using "in_menu: false" > and "no_output: true", but without success as of now. In summary, > if I have N news in the folder, > I get N+1 headlines in my FNP, and the first one is a fake news > corresponding to the index page.Ah, okay. If all page files in your "news" folder are news files except the index.page, you can use the following (replace the fomer version): <% context.content_node.tree.node_access[:alcn].select do |alcn,no| alcn =~ /\/news\/.*\.html/ && no.is_file? && no.acn != ''/news/index.html'' <--- HERE COMES THE REST FROM THE OTHER POST If you need any further help, just write again :-) Best regards, Thomas
Damien Pollet
2009-Nov-28 14:35 UTC
[webgen-users] webgen, include files and "static-changing" pages
Hi all, I''ve been adapting the code here for myself. I have foo.blog pages for entries, and an index page that lists them. In config.yaml I added this: patterns: Page: add: ["**/*.blog"] so that entries are treated like normal pages. But in the output I get foo.blog files that contain the generated html, whereas the bar.page files produce bar.html. Contents is good, but name is wrong? Also, a remark; in the index page I have this: <% pages = context.content_node.tree.node_access[:alcn].select{ |alcn,no| alcn =~ /\d{4}\/.*\.blog/ && no.is_file? } pages = pages.collect{ |na,no| no}.sort{ |a,b| b[''date''] <=> a[''date''] } pages.each do |node| %> ... display stuff from the entry? <% end %> Here I''m not sure I understand the logic? we''re selecting nodes from the rendered output, but get data from the input? Instead, how could I iterate over src nodes? How can I get the src node from an output node (or reverse)? Could I access the original markdown code for a node? Here I think I do not have a clear idea how input nodes get transformed, if they generate nodes for each stage in the rendering pipeline, etc? I''ve been looking through the documentation but it didn''t really help me understand the model behind the generation process? Cheers On Tue, Oct 27, 2009 at 12:44, Thomas Leitner <t_leitner at gmx.at> wrote:>> ? Ok, again it works, with some minor problems and corrections: >> ? 1. Instead of >> ? ? ?>>> ? ? ? ? ? ? ? ? <h1><%= node.title %></h1> >> >> ? ? ? I am using >> ? ? ?>>> ? ? ? ? ? ? ? ? ?<h1><%= node[''routed_title''] %></h1> > > That''s okay but `routed_title` is normally only defined for directory > index files. So you might want to use something like > > ? ?<h1><%= node[''routed_title''] || node[''title''] %></h1> > > And `node.title` naturally doesn''t work ;-) My fault, sorry! > >> ? 2. One problem I could not solve yet is the next line: >> ? ? ? >>> ?Published on <%= node[''created_at''].strftime("%A, %d %B >> %Y") %> - >> >> ? ? ? I keep getting error messages saying that some "nil" class >> doesn''t know the >> ? ?strftime method. But I can live without this. > > Try using the meta information `modified_at` instead of `created_at`. > The former is available on all nodes while the latter has to be set > individually since it cannot be derived. > >> ? 3. Another one is as follows: my FNP includes, on top of actual >> headlines from my news, a "fake" >> ? ? ?headline containing title of the index.html page on my "news" >> folder. I tried using "in_menu: false" >> ? ? ?and "no_output: true", but without success as of now. In summary, >> if I have N news in the folder, >> ? ? ?I get N+1 headlines in my FNP, and the first one is a fake news >> corresponding to the index page. > > Ah, okay. If all page files in your "news" folder are news files except > the index.page, you can use the following (replace the fomer version): > > <% > context.content_node.tree.node_access[:alcn].select do |alcn,no| > ?alcn =~ /\/news\/.*\.html/ && no.is_file? && no.acn != ''/news/index.html'' > <--- HERE COMES THE REST FROM THE OTHER POST > > If you need any further help, just write again :-) > > Best regards, > ?Thomas > _______________________________________________ > webgen-users mailing list > webgen-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/webgen-users >-- Damien Pollet type less, do more [ | ] http://people.untyped.org/damien.pollet
Thomas Leitner
2009-Nov-28 16:17 UTC
[webgen-users] webgen, include files and "static-changing" pages
> I''ve been adapting the code here for myself. I have foo.blog pages for > entries, and an index page that lists them. In config.yaml I added > this: > > patterns: > Page: > add: ["**/*.blog"] > > so that entries are treated like normal pages. But in the output I get > foo.blog files that contain the generated html, whereas the bar.page > files produce bar.html. Contents is good, but name is wrong?This is intentional if you look in the source for the page handler. The extension is only changed to .html if it was .page. However, since you can override how output names are created this is easily fixed; just add the following to a metainfo file: --- name:paths **/*.blog: output_path_style: [:parent, :basename, [''.'', :lang], .html]> Also, a remark; in the index page I have this: > > <% > pages = context.content_node.tree.node_access[:alcn].select{ > |alcn,no| alcn =~ /\d{4}\/.*\.blog/ && no.is_file? } > pages = pages.collect{ |na,no| no}.sort{ |a,b| b[''date''] <=> > a[''date''] } pages.each do |node| > %> > ... display stuff from the entry? > <% end %> > > Here I''m not sure I understand the logic? we''re selecting nodes from > the rendered output, but get data from the input? Instead, how could I > iterate over src nodes? How can I get the src node from an output node > (or reverse)? Could I access the original markdown code for a node? > Here I think I do not have a clear idea how input nodes get > transformed, if they generate nodes for each stage in the rendering > pipeline, etc? I''ve been looking through the documentation but it > didn''t really help me understand the model behind the generation > process?The code does the following: * `context.content_node.tree` returns the internal node tree representation, * `.node_access[:alcn]` returns the hash with the mappings from alcn to Node objects * `.select {...}` selects all file nodes which have a certain alcn (in this case files with four digits, then anything and then .blog) So the `pages` variable contains an array with [alcn, node] pairs of all blog pages. After that * `collect{...}` removes the `alcn` part from the list, * `sort{...}` sorts the nodes by their meta information `date` * `each do ... end` uses the nodes to actually display stuff from the entry What you might not know is that the internal node tree does not contain the source paths! Each source path can create 0..n nodes and these nodes are added to the node tree. Therefore each node is created by exactly one source path (the source path can be retrieved using `node.node_info[:src]`; note that this is a string; to actually get the source Path object for it you have to use `website.blackboard.invoke(:source_paths)[node.node_info[:src]]`). So you have a mapping from one source path (a Webgen::Path object) to zero, one or more Wegen::Node objects which may or may not (depending on the source handler) be written to the output directory. For example, a .page source file currently maps to exactly one node which will be written to the output directory. A .metainfo source file also maps to one node but will not be written to the output. And a .virtual file maps to one or more nodes. If you want to iterate over all source paths, you can use the Hash object returned by `website.blackboard.invoke(:source_paths)`. However, I can''t currently of a situation where you want to do this... If you want to get the unprocessed source of a page node, you can use `node.node_info[:page]` attribute which returns a Webgen::Page object. Hopes this helps a bit in understanding the internal workings of webgen! -- Thomas
Damien Pollet
2009-Nov-29 11:54 UTC
[webgen-users] webgen, include files and "static-changing" pages
On Sat, Nov 28, 2009 at 17:17, Thomas Leitner <t_leitner at gmx.at> wrote:> This is intentional if you look in the source for the page handler. The > extension is only changed to .html if it was .page.OK. I expected a general way to map the source extensions to output ones, but it''s true that the feed handler generates both atom and rss?> * `.node_access[:alcn]` returns the hash with the mappings from alcn to > ?Node objectsJust a design detail here (I''m an OO weenie I guess :D), but why don''t nodes know their alcn? Wouldn''t ?tree.select { |node| node.alcn =~ ?} read nicer? It would also make the following collect unnecessary. With mappings, it does feels strange at first to duplicate the hash key into the value, but I often found it leads to simpler use afterwards. Especially true if there are multiple kinds of keys that make sense depending on the context (I suppose you can do node_access[:lcn] or similar).> exactly one source path (the source path can be retrieved using > `node.node_info[:src]`; note that this is a string; to actually get the > source Path object for it you have to use > `website.blackboard.invoke(:source_paths)[node.node_info[:src]]`).Again, why store the string when the node could directly know its Path (and here I suppose the path can be flattened back to a string)> Hopes this helps a bit in understanding the internal workings of webgen!Yup, very much, thanks! -- Damien Pollet type less, do more [ | ] http://people.untyped.org/damien.pollet
Thomas Leitner
2009-Nov-29 20:27 UTC
[webgen-users] webgen, include files and "static-changing" pages
> > * `.node_access[:alcn]` returns the hash with the mappings from > > alcn to Node objects > > Just a design detail here (I''m an OO weenie I guess :D), but why don''t > nodes know their alcn? > Wouldn''t ?tree.select { |node| node.alcn =~ ?} read nicer? It would > also make the following collect unnecessary. > > With mappings, it does feels strange at first to duplicate the hash > key into the value, but I often found it leads to simpler use > afterwards. Especially true if there are multiple kinds of keys that > make sense depending on the context (I suppose you can do > node_access[:lcn] or similar).Actually, there is a method called `node.alcn` which returns the alcn of a node. However, the tree has a hash for directly accessing the Node object by knowing its alcn. This is useful in a number of cases, for example, when checking if a node alcn is unique or when you only have an alcn and want to get the node. Otherwise I would have to search through the whole tree to get the correct node for an alcn.> > exactly one source path (the source path can be retrieved using > > `node.node_info[:src]`; note that this is a string; to actually get > > the source Path object for it you have to use > > `website.blackboard.invoke(:source_paths)[node.node_info[:src]]`). > > Again, why store the string when the node could directly know its Path > (and here I suppose the path can be flattened back to a string)This has another reason: a source Path object needs access to the source of a path (normally a file but could potentially be something else, for example, a database) and therefore it has an IO object attached. This brings a problem when serializing the whole node tree into the cache file since IO objects can''t serialized! Therefore only the string version of the source path is stored in a Node. -- Thomas