# Simple blog too complex: what does this code do?

**URL:** <https://www.ruby-forum.com/t/simple-blog-too-complex-what-does-this-code-do/88108>\
**Category:** Radiant CMS\
**Created:** [March 8, 2007, 8:59am UTC](https://www.ruby-forum.com/t/simple-blog-too-complex-what-does-this-code-do/88108 "2007-03-08T08:59:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![modhelius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eb9ed0/32.png) [@modhelius](https://www.ruby-forum.com/u/modhelius)\
**Post date:** [March 8, 2007, 8:59am UTC](https://www.ruby-forum.com/t/simple-blog-too-complex-what-does-this-code-do/88108/1 "2007-03-08T08:59:12Z")

</div>

I have based [http://smpl.se](http://smpl.se) on the “simple blog” included in Radiant  
0.6 RC1. There is one piece of code in the “Normal” layout that I  
don’t quite understand:

\<r:if\_url matches=“^/articles/\d{4}/\d{2}/\d{2}/.+”\>\<r:unless\_url  
matches=“-archives/$”\>

Posted by \<r:author /\> on  
\<r:date /\>

\</r:unless\_url\>\</r:if\_url\>

What does it do? I’ve created several “sections” based on the  
‘articles’ section, with a different blog in each (I know I, I should  
be using categories or tags). My ‘articles’ nodes ar called:

[http://smpl.se/blog](http://smpl.se/blog)  
[http://smpl.se/bath](http://smpl.se/bath)  
[http://smpl.se/car](http://smpl.se/car)

Do I need to do anything to that code? Should I remove it?

I feel that some of the default templates are a bit too complex. I’d  
like to reduce the complexity by not requiring a new Radiant-user to  
change a lot of regular expressions - often having to match several  
expressions to each other.

I don’t know if what I’m saying makes sense. I am a new user myself,  
so I’m learning as I go.

Ideally I’d like to see a turnkey install of a simple but very  
capable blogging engine, pared down to the bare esentials. The target  
audience would be both people who want something simple so they can  
start publishing right away, and the crowd who want something simple  
that they can start building on.

I’m going to keep working on smpl.se and see what I come up with.  
Right now it’s a mess, but it’ll get better. I’m only going to work  
on pages, snippets and layouts: I’ll leave the back end to you guys -  
I’d love to talk about it though, if I have any questions or ideas.

Regards,

Martin O.  
[http://smpl.se](http://smpl.se)

---

<div class="post-metadata">

**Author:** ![modhelius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eb9ed0/32.png) [@modhelius](https://www.ruby-forum.com/u/modhelius)\
**Post date:** [March 8, 2007, 11:08am UTC](https://www.ruby-forum.com/t/simple-blog-too-complex-what-does-this-code-do/88108/2 "2007-03-08T11:08:26Z")

</div>

On 3/8/07, Martin O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> There is one piece of code in the “Normal” layout that I  
> don’t quite understand:
> 
> \<r:if\_url matches=“^/articles/\d{4}/\d{2}/\d{2}/.+”\>\<r:unless\_url  
> matches=“-archives/$”\>
> 
> Posted by \<r:author /\> on  
> \<r:date /\>
> 
> \</r:unless\_url\>\</r:if\_url\>

It’s simple really - you read it out like English 🙂

If the current URL starts with “/articles/YYYY/MM/DD” (generic blog  
format),  
print out “Posted by [author] on [date]” in a paragraph. However, the  
URL  
must not end in “-archives/”. This is because archives are pages with  
that  
URL format, too, but you don’t want them to look like blog posts.

---

<div class="post-metadata">

**Author:** ![modhelius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eb9ed0/32.png) [@modhelius](https://www.ruby-forum.com/u/modhelius)\
**Post date:** [March 8, 2007, 2:51pm UTC](https://www.ruby-forum.com/t/simple-blog-too-complex-what-does-this-code-do/88108/3 "2007-03-08T14:51:02Z")

</div>

So what do I do to make it work with a “multi-blog” site? I need  
something that matches /blog/YYYY/MM/DD, /blog/YYYY/MM/DD, /car/YYYY/  
MM/DD, and I don’t really want to have to change it or add to it  
every time I add a new “project blog”.

Regards,  
Martin O.  
[http://smpl.se](http://smpl.se)

---

<div class="post-metadata">

**Author:** ![modhelius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eb9ed0/32.png) [@modhelius](https://www.ruby-forum.com/u/modhelius)\
**Post date:** [March 8, 2007, 2:54pm UTC](https://www.ruby-forum.com/t/simple-blog-too-complex-what-does-this-code-do/88108/4 "2007-03-08T14:54:03Z")

</div>

Change the first part of the if\_url to look like so:

\<r:if\_url  
matches="^/(blog|car|whatever)/\d{4}/\d{2}/\d{2}/.+"\>\<r:unless\_url  
matches="-archives/$"\>

Posted by \<r:author /\> on  
\<r:date /\>

\</r:unless\_url\>\</r:if\_url\>

You can keep chaining on other “categories” with the | character.

Sean

---

<div class="post-metadata">

**Author:** ![modhelius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eb9ed0/32.png) [@modhelius](https://www.ruby-forum.com/u/modhelius)\
**Post date:** [March 8, 2007, 4:12pm UTC](https://www.ruby-forum.com/t/simple-blog-too-complex-what-does-this-code-do/88108/5 "2007-03-08T16:12:16Z")

</div>

You could replace anything inside those parens with an appropriate  
character class… probably [\w-]+ would work.

Sean

---

<div class="post-metadata">

**Author:** ![modhelius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eb9ed0/32.png) [@modhelius](https://www.ruby-forum.com/u/modhelius)\
**Post date:** [March 8, 2007, 4:09pm UTC](https://www.ruby-forum.com/t/simple-blog-too-complex-what-does-this-code-do/88108/6 "2007-03-08T16:09:15Z")

</div>

Thanks! I know how to write regular expressions. I was wondering if  
there was a way to make this more automatic. The DRY-principles  
should apply to layouts as well, no? Can anyone think of a way to  
reduce the number of places I need to change when I add a new project  
blog. Right now I do this:

Create a new child of the root, say “food”.  
Copy the content from a previous blog, say “cars”.  
Change some stuff in the page content.  
Create an RSS-feed.  
Change the Normal layout.

I’d like to find a smarter and less redundant way to do this.

/Martin  
[http://smpl.se](http://smpl.se)

---

<div class="post-metadata">

**Author:** ![modhelius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eb9ed0/32.png) [@modhelius](https://www.ruby-forum.com/u/modhelius)\
**Post date:** [March 8, 2007, 5:36pm UTC](https://www.ruby-forum.com/t/simple-blog-too-complex-what-does-this-code-do/88108/7 "2007-03-08T17:36:27Z")

</div>

… or you could just use the regexp without the  
first part: “/\d{4}/\d{2}/\d{2}/”
