Hi Sylvain, I hope I understand what you are trying to do. But here is what I would suggest. 1) Think about how you are going to structure your blog content ahead of time. I would suggest something like /content/blog/year/month/post/comments. This way your archive script does not need to query the repository but will simply know how to construct a path to a specific year (and month). 2) You could use a Sling URL selector for the year (example: /content/archives.2014.html where /content/archives has sling:resourceType = “blog/year-archive”). Sling provides API for getting URL selectors from request. This way /etc/map stuff is not needed. But either way your script will still have to extract the year from request. I don’t see any way around this. The selector based approach is an alternative to your /etc/map bridge if you don’t like it. But, actually, selectors seem to be less intuitive for end users in this case. You could also use suffixes (i.e. /content/archives.html/2014). 3) I would not actually store content with any particular markup. Just use default JCR backed Resource implementation and think of a blog post in terms of JCR nodes/properties (or resources/properties if you prefer higher level of abstraction :)). You should have a resource type like /apps/blog/post with scripts for rendering different markups if you want. Alternatively you could have just html rendering script (html.esp ?) and use Sling rewriter pipeline (http://sling.apache.org/site/output-rewriting-pipelines-orgapacheslingrewriter.html) to generate other markups. A resource like /content/blog/year/month/post should have sling:resourceType = “blog/post”. You don’t need an observation listener that generates and stores different markups. It’s also quite a bit of extra content you don’t need to store if you render markup when it’s requested. 4) You also don’t need separate authoring and publish areas if you structure posts content as I suggested. All new posts should be created under /content/blog/currentYear/currentMonth/ anyway. This is both your blog’s authoring and publish/archive area. A basic implementation of an authoring script can be just an HTML form that does a POST to sling repository using default Sling Post Servlet - http://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html. You have a lot of control over how you structure content via this mechanism.
I hope this helps. Henry On Dec 27, 2014, at 11:46 AM, Sylvain Wallez <[email protected]> wrote: > Hi all, > > I'm discovering Sling these days (it's never too late!), and as a playground > I'm trying to implement a blog engine that goes further than the espblog > sample, with support for archive pages, comments and writing content in > different markup languages (html, markdown and asciidoc). > > I quite like the resource-centric approach, which makes it easy to quickly > create content and presentation scripts, but I didn't find an obvious > solution for archive pages which are synthetic content resulting from a query > in the content repository. I'd be grateful if you guys could provide some > best practices. > > Here's how I implemented it : > > - a mapping "/etc/map/year-archive" with properties: > - "sling:match" = ".*/archives/[0-9]+" > - "sling:internalRedirect" = "/archives/year-archive.html" > > - a resource "/archive/year-archive" with "sling:resourceType" = > "blog/year-archive" > > - a script "/app/blog/year-archive/html.esp" that extracts the year from > request.pathInfo and uses that information to query the repository for > matching posts and builds the archive list. > > It works but sounds a bit hacky to me : "/archive/year-archive" is used only > as a bridge between the redirect and the script, and the script has to re-do > pathInfo pattern matching to extract the year number. Is there a simpler way > to implement this ? > > Next I'm wondering how to implement multiple markup formats for content: > markdown and asciidoc end up being translated to html and formated using the > same template as raw html content, but how/where to implement the markup -> > html transformation? > > From what I understand a content resource cannot be transformed before being > fed to the template script, so I thought to have two separate areas in the > content repository : > - an "authoring" area where the original content is stored > - an observer listens to that area, transforms the markdown/asciidoc content > to html and is stores it in a "publish" area > - the "publish" area is the one that is actually rendered and published on > the web. > > Is this the way to go? Also, is it possible to write such an observer as a > script, or does it have to be a Java class packaged in a new bundle? > > Thanks in advance for your guidance and sorry for these noob questions :-) > > Sylvain > > -- > Sylvain Wallez - http://bluxte.net >
