Antville Project

Friday, 11. October 2002

prototype implementation of autoTitle

this belongs to this story, but it's too long for the frontpage and to wide for a comment, so i put it here :-)

i implemented the feature mentioned there in my local antville installation by modifying link_macro(param) in hopobject/macros.js to use a new function linkTitle(url) that i put into hopobject/objectFunctions for the sake of simplicity. i guess this is the wrong place to do this, because it only works with <% site.link %>, but not with <% link %>. anyway, the code itself works fine, so here it is:

link_macro as it was before:

function link_macro(param) {
  if (param.checkdeny == "true") {
    if (this.isDenied(session.user))
      return("");
  }
  var content = param.text ? param.text : param.to;
  param = this.createLinkParam(param);
  openMarkupElement("a", param);
  res.write(content);
  closeMarkupElement("a");
}

and the new version:

function link_macro(param) {
  if (param.checkdeny == "true") {
    if (this.isDenied(session.user))
      return("");
  }
  var content = param.to;
  if (param.text) {
    content = param.text;
  } else if (param.autoTitle != "off") {
    var linkTitle = this.linkTitle(param.to);
    if (linkTitle) {
      content = linkTitle;
    }
  }
  param = this.createLinkParam(param);
  openMarkupElement("a", param);
  res.write(content);
  closeMarkupElement("a");
}

and here's linkTitle:

/**
 * return title of linked object or null if it has no
 * title.
 * so far, only titles of stories are extracted, but this
 * could be extended to also return titles of topic-frontpages,
 * external html pages (those titles would have to be
 * cached) etc.
 */
function linkTitle(url) {
   if (!url) {
      return null;
   }
   var iFirstSlash = url.indexOf("/");
   if (url.substring(0, iFirstSlash) != "stories") {
      return null;
   }
   var rest = url.substring(iFirstSlash + 1, url.length);
   var storyNum = parseInt(rest);
   if (isNaN(storyNum)) {
      return null;
   }
   var story = path.site.stories.get(String(storyNum));
   return story.getContentPart("title");
}

hope this helps. i'd love to see that in antville!

link (no comments) 
 

autoTitle

when i link to a story like this: <% site.link="stoies/59/" %> i get a link that looks like this: stories/59/ however, i'd like to have an "autoTitle" feature that automatically makes a link looking like this: next steps because this is the title of the story. of course, i can always override the default link text with the "text" parameter, but if the title of the story changes, the link becomes wrong. so, an autoTitle feature wouldn't just save me from typing in the title, it would do more. and if i want to turn that feature off because i want to display the actual URL, i want to use this: <% site.link to="stories/59/" autoTitle="off" %>

i' posted a working implementation of this feature there.

link (6 comments
 

Featureitis again

When writing a function for an Antville object, if i have the number of a story (e.g. story #3 is the one at mysite/stories/3/), how can i get a reference to the story object itself? I'm looking for something like path.site.getStory(storyNum).

link (4 comments
 

The Antville Server Fund has been a great success. Thanks to everybody who contributed!
online for 8549 Days
last updated: 1/4/11, 10:22 AM
status
Youre not logged in ... Login
menu
October 2002
SunMonTueWedThuFriSat
12345
6789101112
13141516171819
20212223242526
2728293031
SeptemberNovember
recent
zfuture's house here is zfuture's
house
by zfuture (7/31/03, 2:59 AM)
i understand your concerns however,
i hardly can think of a solution. certainly, if the...
by tobi (7/29/03, 9:47 AM)
Found several more similar sites
listed This is getting to be quite a concern to...
by cobalt123 (7/27/03, 7:56 PM)
Second Post Alert on Referrer
bug livecatz I put this into "help" and now here:...
by cobalt123 (7/26/03, 7:14 PM)
well it's not easy to
find from here, anyway. think we should include a link,...
by tobi (7/24/03, 11:25 AM)
So finally I found
the helma Bugzilla - stupid me.
by mdornseif (7/24/03, 10:28 AM)
clock not that it's particularly
earthshattering but the antclock is running slow by about 15...
by kohlehydrat (7/23/03, 8:25 PM)
but blogosphere.us isn't can't really
be rated as spam can it?
by kohlehydrat (7/23/03, 8:08 PM)
More referrer spam www.webfrost.com
by Irene (7/23/03, 7:55 PM)
How to log skin names
I accessed to console?? Hi, I would like to know...
by winson (7/23/03, 4:12 PM)

Click here to get an XML version of this weblog.

Made with Antville
powered by
Helma Object Publisher