Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
tweaking ForEachTiddler title displays to ignore initial articles?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mark  
View profile  
 More options Jan 9 2008, 4:32 pm
From: Mark <mckel...@gmail.com>
Date: Wed, 9 Jan 2008 13:32:20 -0800 (PST)
Local: Wed, Jan 9 2008 4:32 pm
Subject: tweaking ForEachTiddler title displays to ignore initial articles?
I'm a beginner in learning JavaScript and am in need of some advanced
expertise.

I'm using the ForEachTiddler plugin to generate a list book titles.

The book titles are entered as the titles of the tiddlers.

The current display of a large volume of initial articles is annoying:
to many A's, An's and The's.

Searching around I found a bit of Javascript someone cooked up to
address this issue within the context of an online library catalog:

"I have updated the script to ignore initial articles. I updated the
sort_alpha function thusly:

sort_alpha: function(a,b) {
if (a[0].substring(0,2) == "A ") {
a[0] = a[0].substring(2,a[0].length);

}

if (b[0].substring(0,2) == "A ") {
b[0] = b[0].substring(2,b[0].length);
}

if (a[0].substring(0,3) == "An ") {
a[0] = a[0].substring(3,a[0].length);
}

if (b[0].substring(0,3) == "An ") {
b[0] = b[0].substring(3,b[0].length);
}

if (a[0].substring(0,4) == "The ") {
a[0] = a[0].substring(4,a[0].length);
}

if (b[0].substring(0,4) == "The ") {
b[0] = b[0].substring(4,b[0].length);
}

if (a[0].toUpperCase()==b[0].toUpperCase()) return 0;
if (a[0].toUpperCase()<b[0].toUpperCase()) return -1;
return 1;

},

They state: "There are probably more elegant ways to do this but I'm a
real hack when it comes to javascript! ;)"

From: http://www.innopacusers.org/list/archives/2007/msg07085.html

Is there an elegant way to include such a script with a FET macro
call?

Thanks in advance,

Mark


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Shulman  
View profile  
 More options Jan 10 2008, 1:12 am
From: Eric Shulman <elsdes...@gmail.com>
Date: Wed, 9 Jan 2008 22:12:18 -0800 (PST)
Local: Thurs, Jan 10 2008 1:12 am
Subject: Re: tweaking ForEachTiddler title displays to ignore initial articles?
Try this:

sort_alpha: function(a,b) {
   a[0]=a[0].replace(/^(A|An|The) /,"");
   b[0]=b[0].replace(/^(A|An|The) /,"");
   if (a[0].toUpperCase()==b[0].toUpperCase()) return 0;
   if (a[0].toUpperCase()<b[0].toUpperCase()) return -1;
   return 1;

}

-e
Eric Shulman
TiddlyTools / ELS Design Studios

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark  
View profile  
 More options Jan 10 2008, 4:02 am
From: Mark <mckel...@gmail.com>
Date: Thu, 10 Jan 2008 01:02:12 -0800 (PST)
Local: Thurs, Jan 10 2008 4:02 am
Subject: Re: tweaking ForEachTiddler title displays to ignore initial articles?
Thanks Eric!

Now, please excuse my ignorance but how exactly would I embed this
script to ignore initial articles into a FET macro call like the
following one?

<tab B>
<<forEachTiddler
where
 'tiddler.title.startsWith("B") && tiddler.tags.contains("book")'


</tab>

The example provided in my initial post was from a different context
that I do not need to replicate. It was some Javascript that I thought
might illustrate in a general way what I was trying to do.

Thanks again for your assistance.

Your fluency inspires me to dive deeper into these mysteries.

mck

On Jan 9, 10:12 pm, Eric Shulman <elsdes...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Shulman  
View profile  
 More options Jan 10 2008, 4:55 am
From: Eric Shulman <elsdes...@gmail.com>
Date: Thu, 10 Jan 2008 01:55:20 -0800 (PST)
Local: Thurs, Jan 10 2008 4:55 am
Subject: Re: tweaking ForEachTiddler title displays to ignore initial articles?

> Now, please excuse my ignorance but how exactly would I embed this
> script to ignore initial articles into a FET macro call like the
> following one?

OK... try this:

<tab B>
<<forEachTiddler
where
'tiddler.title.replace(/^(A|An|The) /,"").startsWith("B") &&
tiddler.tags.contains("book")'>>
</tab>

enjoy,
-e


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark  
View profile  
 More options Jan 10 2008, 6:14 am
From: Mark <mckel...@gmail.com>
Date: Thu, 10 Jan 2008 03:14:10 -0800 (PST)
Local: Thurs, Jan 10 2008 6:14 am
Subject: Re: tweaking ForEachTiddler title displays to ignore initial articles?
Almost there!

It now works for: The Book of Job (upper case)

but the following titles get dropped where the second word contains a
lowercase b:

The butcher, the baker, the candlestick maker
The broken chalice

Also, all the titles beginning with ( The ) are currently displaying
at the end of the list rather than within proper alphabetic sequence.

For instance, they now sort like this:

# Creativity and its role in healing
# Crucial work
# Curia anima
# The Cartesian ghost in transference and projective identification
# The Cassandra complex
# The Celtic landscape

rather than:

# The Cartesian ghost in transference and projective identification
# The Cassandra complex
# The Celtic landscape
# Creativity and its role in healing
# Crucial work
# Curia anima

It's 3 am so perhaps if I sleep on this one ....

Thanks again!

Mark

On Jan 10, 1:55 am, Eric Shulman <elsdes...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Shulman  
View profile  
 More options Jan 10 2008, 8:49 am
From: Eric Shulman <elsdes...@gmail.com>
Date: Thu, 10 Jan 2008 05:49:24 -0800 (PST)
Local: Thurs, Jan 10 2008 8:49 am
Subject: Re: tweaking ForEachTiddler title displays to ignore initial articles?

> It now works for: The Book of Job (upper case)
> but the following titles get dropped where the second word contains a
> lowercase b:

The startsWith() function (defined by ForEachTiddlerPlugin) does a
case-sensitive comparison...  Thus,
  tiddler.title.replace(/^(A|An|The) /,"").startsWith("B")
only checks for *upper case* B

For case-insensitive single-letter comparisons, you should skip this
function and use:
   tiddler.title.replace(/^(A|An|
The) /,"").substr(0,1).toUpperCase()=="B"

> Also, all the titles beginning with ( The ) are currently displaying
> at the end of the list rather than within proper alphabetic sequence.

The "where" clause filters the title (to remove the A/An/The prefix)
for comparison purposes ONLY.  It does not actually alter the titles
in the resulting list, and doesn't change the *sort order* of the
list.  You will need to add a custom "sortBy" clause to your
<<ForEachTiddler>> usage so that it also filters out the prefix (if
any) for sorting purposes (without altering the actual titles in the
list)

Putting it together:

<tab B>
<<forEachTiddler
   where
      'tiddler.title.replace(/^(A|An|
The) /,"").substr(0,1).toUpperCase()=="B" &&
tiddler.tags.contains("book")'
   sortBy
      tiddler.title.replace(/^(A|An|The) /,"")>>
</tab>

enjoy,
-e


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark  
View profile  
 More options Jan 10 2008, 12:47 pm
From: Mark <mckel...@gmail.com>
Date: Thu, 10 Jan 2008 09:47:47 -0800 (PST)
Local: Thurs, Jan 10 2008 12:47 pm
Subject: Re: tweaking ForEachTiddler title displays to ignore initial articles?
That's it!

The last part did not work until I wrapped it in '   '.

Now, it works like a charm.

<tab B>
<<forEachTiddler
where
      'tiddler.title.replace(/^(A|An|
The) /,"").substr(0,1).toUpperCase()=="A" &&
tiddler.tags.contains("book")'
   sortBy
 'tiddler.title.replace(/^(A|An|The) /,"")'>>
</tab>

For a 1200 item bibliography, this little bit of Javascript will save
me hours of work and results and a much more professional display.

Thanks, Eric!

Mark

On Jan 10, 5:49 am, Eric Shulman <elsdes...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark  
View profile  
 More options Jan 10 2008, 3:08 pm
From: Mark <mckel...@gmail.com>
Date: Thu, 10 Jan 2008 12:08:11 -0800 (PST)
Local: Thurs, Jan 10 2008 3:08 pm
Subject: Re: tweaking ForEachTiddler title displays to ignore initial articles?

Oops.

I spoke to soon.

The sortBy clause is not quite right.

It works well where the second word is upper case:

* Caring for the vulnerable child in the critical hours
* The Cartesian ghost in transference and projective identification
* The Cassandra complex
* Cat's eye

but then at the end of the list appear all the instances where the
second word is lower case.

* Creativity its role in healing
* Curia anima
* The case of the murdered ox: the Athenian Bouphonia: a contribution
to ecopsychology
* A chance to say goodbye
* The consulting room as a theater for the Greek tragedy play

What do I need to add to the sort clause so that the case of the first
word after the initial articles (A, An, The) makes no difference to
the alphabetic sort order?

Thus, in the end, the titles should sort as follows:

* Caring for the vulnerable child in the critical hours
* The Cartesian ghost in transference and projective identification
* The Cassandra complex
* Cat's eye
* A chance to say goodbye
* The consulting room as a theater for the Greek tragedy play
* Creativity its role in healing
* Curia anima

I'm sure what would take me days is actually a very quick and simple
fix.

Thanks in advance!

Mark

On Jan 10, 9:47 am, Mark <mckel...@gmail.com> wrote:

-e

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Shulman  
View profile  
 More options Jan 10 2008, 3:13 pm
From: Eric Shulman <elsdes...@gmail.com>
Date: Thu, 10 Jan 2008 12:13:23 -0800 (PST)
Local: Thurs, Jan 10 2008 3:13 pm
Subject: Re: tweaking ForEachTiddler title displays to ignore initial articles?

> The sortBy clause is not quite right.
> It works well where the second word is upper case:
> but then at the end of the list appear all the instances where the
> second word is lower case.
> What do I need to add to the sort clause so that the case of the first
> word after the initial articles (A, An, The) makes no difference to
> the alphabetic sort order?

add ".toUpperCase()" to the sortBy expression, like this:

sortBy 'tiddler.title.replace(/^(A|An|The) /,"").toUpperCase()'>>

enjoy,
-e


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark  
View profile  
 More options Jan 10 2008, 4:23 pm
From: Mark <mckel...@gmail.com>
Date: Thu, 10 Jan 2008 13:23:02 -0800 (PST)
Local: Thurs, Jan 10 2008 4:23 pm
Subject: Re: tweaking ForEachTiddler title displays to ignore initial articles?
Perfect!

Your javascript juju does indeed bring joy!

Many thanks!

Mark

<<forEachTiddler
where
      'tiddler.title.replace(/^(A|An|
The) /,"").substr(0,1).toUpperCase()=="A" &&
tiddler.tags.contains("book")'
   sortBy
 'tiddler.title.replace(/^(A|An|The) /,"").toUpperCase()'>>

On Jan 10, 12:13 pm, Eric Shulman <elsdes...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »