Frank Ellebrecht
2012-Jun-28 10:08 UTC
[webgen-users] How to set link_attrs: :link_text: with ruby?
Hello, Sorry to bother you again. How do I set something like link_attrs: :link_text: Some text with ruby? In the blog code by Matteo Collina you''ll find blog_nodes.each do |node| node["title"] = tag end and I would like to add node["link_attrs:link_text"] = "Entries in category #{tag}" so that the :link_text: metainfo shows up in the sitemap and the breadcrumb trail. I tried various combinations in "node[...]" but it seems I missed the right one. :-( Thanks again for your great support, Thomas! Kind regards, Frank
Thomas Leitner
2012-Jun-28 10:44 UTC
[webgen-users] How to set link_attrs: :link_text: with ruby?
On 2012-06-28 12:08 +0200 Frank Ellebrecht wrote:> Hello, > > Sorry to bother you again. > > How do I set something like > > link_attrs: > :link_text: Some text > > with ruby? In the blog code by Matteo Collina you''ll find > > blog_nodes.each do |node| > node["title"] = tag > end > > and I would like to add > > node["link_attrs:link_text"] = "Entries in category #{tag}" > > so that the :link_text: metainfo shows up in the sitemap and the > breadcrumb trail. I tried various combinations in "node[...]" but it > seems I missed the right one. :-(The meta information on top of a page file is in YAML format, more precisely, a YAML hash is expected. This YAML hash gets read and converted to a native Ruby hash, accessible via the Node#[] method. So your example input above would add the ''link_attrs'' meta info: node[''link_attrs''] # => {:link_text => ''Some text''} To change the link text, you would need to do the following: (node[''link_attrs''] ||= {})[:link_text] = "Entries in category #{tag}" This ensures that the ''link_attrs'' meta information is set to an empty hash if it is no already initialized and then sets the :link_text sub key to the given string Best regards, Thomas
Frank Ellebrecht
2012-Jun-29 10:17 UTC
[webgen-users] How to set link_attrs: :link_text: with ruby?
Hello Thomas, Thank you for the explanation and the example code. Do I have to say that it worked? Of course it did, thanks. But as I had to realize that I would have to change some other things in the blog code as well, I''ll leave it for now. Maybe I''ll grab a book about ruby and try it again later. It would only have been a nice to have feature, and hey, who looks at the sitemap? ;-) Regards, Frank Am 28.06.2012 12:44, schrieb Thomas Leitner:> On 2012-06-28 12:08 +0200 Frank Ellebrecht wrote: >> Hello, >> >> Sorry to bother you again. >> >> How do I set something like >> >> link_attrs: >> :link_text: Some text >> >> with ruby? In the blog code by Matteo Collina you''ll find >> >> blog_nodes.each do |node| >> node["title"] = tag >> end >> >> and I would like to add >> >> node["link_attrs:link_text"] = "Entries in category #{tag}" >> >> so that the :link_text: metainfo shows up in the sitemap and the >> breadcrumb trail. I tried various combinations in "node[...]" but it >> seems I missed the right one. :-( > > The meta information on top of a page file is in YAML format, more > precisely, a YAML hash is expected. This YAML hash gets read and > converted to a native Ruby hash, accessible via the Node#[] method. > > So your example input above would add the ''link_attrs'' meta info: > > node[''link_attrs''] # => {:link_text => ''Some text''} > > To change the link text, you would need to do the following: > > (node[''link_attrs''] ||= {})[:link_text] = "Entries in category #{tag}" > > This ensures that the ''link_attrs'' meta information is set to an empty > hash if it is no already initialized and then sets the :link_text sub > key to the given string > > Best regards, > Thomas > _______________________________________________ > webgen-users mailing list > webgen-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/webgen-users
Thomas Leitner
2012-Jun-29 11:37 UTC
[webgen-users] How to set link_attrs: :link_text: with ruby?
On 2012-06-29 12:17 +0200 Frank Ellebrecht wrote:> But as I had to realize that I would have to change some other things > in the blog code as well, I''ll leave it for now. Maybe I''ll grab a > book about ruby and try it again later. It would only have been a > nice to have feature, and hey, who looks at the sitemap? ;-)I''m currently working on the next version of webgen which changes quite a bit but will provide a more stable API for future versions (next one will probably be 1.0.0 and not 0.6.0). A blog extension will definitely be available for this version (and yes, I know, I have said this for the 0.4.x and 0.5.x versions, too, but as they say: third time''s a charm! ;-). There are already two extension bundles [1] [2] available although the next version itself is still not released. This would also be a good time to tell me what you would like to see in the next version of webgen ;-) Best regards, Thomas [1]: https://github.com/gettalong/webgen-content_processor_emoticon-bundle [2]: https://github.com/gettalong/webgen-sass_twitter_bootstrap-bundle