incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From couchdb user <couchdbu...@gmail.com>
Subject Re: Best way to store permalinks?
Date Mon, 15 Nov 2010 03:33:53 GMT
Hi Nolan,

I haven used the rewrite option in couchdb yet but you may want to
check the couchdb log to see if the rewrite is working as you expect
it. Sorry I cannot be more helpful.

Regards,



On Wed, Nov 10, 2010 at 11:32 PM, Nolan Darilek <nolan@thewordnerd.info> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hey folks. I've asked this in a couple different IRC channels and on
> the couchapp list, but never received an answer. So I'm assuming that
> this list has a broader subscriber base, and that perhaps someone here
> can help.
>
> I'm trying to migrate my blog into a couchdb, and trying to serve it
> up via a couch app. I'm doing it from scratch both as a learning
> experience, and because there are some aspects of Sofa that I don't like.
>
> One such is its permalinks. My existing blog has a fairly generic
> permalink structure (I.e.):
>
> /yyyy
> /yyyy/mm
> /yyyy/mm/dd
> /yyyy/mm/dd/article-title/
> /about
> /contact
> ...
>
> I've migrated all of my posts into the database, and I have the
> date-based permalinks working nicely via a byDate view. I'm failing on
> page/article permalinks, though. Here's the map view I'm using:
>
> function(doc) {
>  // !code lib/util.js
>  emit(permalink(doc), doc)
> }
>
> And the permalink() functions. I'm new to JS, so pardon any newbie-isms:
>
> function normalizeString(str) {
>  return str.toLowerCase().replace(" ", "-").replace(/![a-z0-9]/, "")
> }
>
> function pad(n) { return (n < 10) ? "0"+n: n.toString() }
>
> function permalink(doc) {
>  if(doc.permalink)
>    return "/"+doc.permalink
>  else if(doc.type && doc.type == "post") {
>    var createdAt = new Date(doc.createdAt)
>    var title = normalizeString(doc.title)
>    var month = pad(createdAt.getMonth()+1)
>    var day = pad(createdAt.getDate())
>    return "/"+createdAt.getFullYear()+"/"+month+"/"+day+"/"+title+"/"
>  } else {
>    return "/"+doc._id
>  }
> }
>
> If I hit the view directly, I get back a list of permalinks:
>
> {"total_rows":14,"offset":0,"rows":[
> {"id":"13e93fae-1dee-4805-8de0-66d8dc2f7c3f","key":"/2009/07/02/announcing-utterance/","value":{"_id":"13e93fae-1dee-4805-8de0-66d8dc2f7c3f","_rev":"14-bd7c1b4494b1190a05bb09c9fc1e8c2a","body":"No,
> this isn't the major post I
> ...
>
> And if I hit the view with a permalink key, I get back the specific
> document:
>
> I also have a list function that renders articles to pages. I can hit
> this list function with a permalink as the key and it works.
>
> I can't for the life of me get a rewrite rule to work with this,
> though. The closest I've come is:
>
>  {
>    "from": "/:year/:month/:day/:title",
>    "to" : "_list/page/permalink",
>    "query": {
>      "key": "\":year/:month/:day/:title\""
>    }
>  },
>
> curl
> localhost:5984/blog/_design/blog/_rewrite/2009/07/02/announcing-utterance/
> (with and without final /)
>
> And when I say that's the best, I mean that it returns HTML. I just
> get a page with my header and footer, but nothing for the page content
> (I.e. a blank spot where the article should be.) At least it doesn't
> tell me my JSON is invalid. I've also tried including or excluding /
> on the ends of the key. I don't even know if the rewrite rules include
> those in the beginning and end, but either I didn't do something
> correctly or something is horribly broken, because no permutation of /
> seemed to make a difference.
>
> I've been working at this for over a week. Can anyone point me in the
> right direction? I've read the wiki, but there's a bit of a last mile
> issue in so much of the docs, as they'll mention that something sends
> "req" as a parameter, only you have to visit another non-linked-to
> page to find out what form that takes. The rewrite docs include lots
> of a=b,c=d types of examples, but practical ones would be more helpful
> to me. I'm wondering, for instance, if I can just use "*" instead? Not
> all of my articles will be posts, and I'd like to link to
> explicitly-set permalinks if possible. Or do I need to store
> permalinks as an array of path components?
>
> If there's anything else I can provide then let me know.
>
> Thanks.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkzbcfIACgkQIaMjFWMehWKKkQCgh5vqLMbR0OaudaICKLoHS06Q
> 40cAmwe01JytI1XczjYFqUg5MU2Iiobn
> =tlxj
> -----END PGP SIGNATURE-----
>
>
>

Mime
View raw message