Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 46978 invoked from network); 15 Nov 2010 03:33:51 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 15 Nov 2010 03:33:51 -0000 Received: (qmail 12386 invoked by uid 500); 15 Nov 2010 03:34:21 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 12210 invoked by uid 500); 15 Nov 2010 03:34:20 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 12199 invoked by uid 99); 15 Nov 2010 03:34:19 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Nov 2010 03:34:19 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of couchdbuser@gmail.com designates 209.85.216.52 as permitted sender) Received: from [209.85.216.52] (HELO mail-qw0-f52.google.com) (209.85.216.52) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Nov 2010 03:34:14 +0000 Received: by qwj8 with SMTP id 8so4239422qwj.11 for ; Sun, 14 Nov 2010 19:33:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=+wPa9bGOGlUg0R7+4NMWLOSycVT9bltMaPpmlnM9kmI=; b=V1Ch47/lD+gnSr2UUMyZ0AGezu1u5qjeNmUWXQ7gh1QgzfZmEBnaWS0R4dqE3aiYqo 6AeAeoL7JjmaOfA3DoF5aX/TE9+1Owkre54MbMcQoPx6HKsPPC+JjOHsth460M4L+a5Z /P3jSCPwxpWFENZxG/q2oWZqgVyOobVO7oS5E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=PGbUnKvM6gPrVTDQo9yrFW/JlJyjPVSXScr4HIEj9cKKKYdAS/vzcHHDfsrt5h9zIJ wVpnha/qjjYZF1hGuDOa34YXnigv7Ar9MjSJJoLXe5LxwQJf9WfVAA0sICWOc4DjwQc7 vf4WMj6FCJ3Ot25lVj9pEw0Qay5l2Mf7rMchI= MIME-Version: 1.0 Received: by 10.229.224.137 with SMTP id io9mr4578094qcb.206.1289792033362; Sun, 14 Nov 2010 19:33:53 -0800 (PST) Received: by 10.229.17.14 with HTTP; Sun, 14 Nov 2010 19:33:53 -0800 (PST) In-Reply-To: <4CDB71F5.2040006@thewordnerd.info> References: <4CDB71F5.2040006@thewordnerd.info> Date: Sun, 14 Nov 2010 22:33:53 -0500 Message-ID: Subject: Re: Best way to store permalinks? From: couchdb user To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 wr= ote: > -----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) { > =A0// !code lib/util.js > =A0emit(permalink(doc), doc) > } > > And the permalink() functions. I'm new to JS, so pardon any newbie-isms: > > function normalizeString(str) { > =A0return str.toLowerCase().replace(" ", "-").replace(/![a-z0-9]/, "") > } > > function pad(n) { return (n < 10) ? "0"+n: n.toString() } > > function permalink(doc) { > =A0if(doc.permalink) > =A0 =A0return "/"+doc.permalink > =A0else if(doc.type && doc.type =3D=3D "post") { > =A0 =A0var createdAt =3D new Date(doc.createdAt) > =A0 =A0var title =3D normalizeString(doc.title) > =A0 =A0var month =3D pad(createdAt.getMonth()+1) > =A0 =A0var day =3D pad(createdAt.getDate()) > =A0 =A0return "/"+createdAt.getFullYear()+"/"+month+"/"+day+"/"+title+"/" > =A0} else { > =A0 =A0return "/"+doc._id > =A0} > } > > 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/announcin= g-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: > > =A0{ > =A0 =A0"from": "/:year/:month/:day/:title", > =A0 =A0"to" : "_list/page/permalink", > =A0 =A0"query": { > =A0 =A0 =A0"key": "\":year/:month/:day/:title\"" > =A0 =A0} > =A0}, > > 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=3Db,c=3Dd types of examples, but practical ones would be more helpfu= l > 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 > =3Dtlxj > -----END PGP SIGNATURE----- > > >