Friday, December 24, 2010

[Javascript] Playing with my blog

While adding these sub-blogs, I have been playing with javascript, trying to learn to modify the site a bit more to my liking. One problem I noticed was that some blog posts may be covered by multiple blog topics(PSP and Programming, for instance) and I would need to have the comments in the main blog, not in the sub-blogs. I also wanted a nice menu at the top that would highlight which site you were one, similar to the pages widget, but a link-list doesn't do that. So I wrote my own two little scripts to fix this.

First, the menu. It was good practice, I was having trouble comparing strings at first, but I found my flaws and eventually got it working.



All you have to do to modify this for your own blog is change the menu entries
The first big half of the if statement is split in two, the first part is checking you are on the right page, second for preventing main blog pages from showing as "Home", since pages from the main blog will also be in the menu. The second half is to check for those main pages, since the first half disallows pages.

I know this is probably overly complicated, but oh well :P It's one of my first attempts at javascript, so sue me.

Next is the comments. That was a simple fix, because of Blogger's standard directory structure.



It checks if you are on a post page by looking for the slashes 5 and 8 characters after the end of the base URL, and if you are, it creates a link to the post on the main blog, and draws the widget. I also added my own personal rule to ignore "new-sub-blog" posts, as those are the first posts on each of my blogs, and I don't plan to mirror them.

To customize this one you just need to change the main blog URL, and the numbers. The first one is the length of the current sub-blogs base URL.("http://nymphaea-programming.blogspot.com/" for this one) The next ones are this number plus 4 and 7, then the first number again.

Who knows I might end up playing more with Javascript on my blog, but until then, I'm done :P

No comments:

Post a Comment