Modify

Opened 18 years ago

Closed 18 years ago

Last modified 13 years ago

#313 closed enhancement (fixed)

Blog "title" in the URL

Reported by: Alec Thomas Owned by: John Hampton
Priority: low Component: TracBlogPlugin
Severity: minor Keywords:
Cc: Trac Release: 0.9

Description

A lot of blog entries seem to have a portion of the title inserted into the URL, after a little munging. For example.

You could add an extra magic formatting symbol to the Page Name Format String (eg. %@) which substitutes the munged page title.

I've attached a quick patch which does this, unfortunately if you update the entry title after it's been substituted into the page name, the new title won't be substituted. Dunno what to do about that, if anything.

Attachments (1)

page-title.diff (1.6 KB) - added by Alec Thomas 18 years ago.
Implementation of concept

Download all attachments as: .zip

Change History (6)

Changed 18 years ago by Alec Thomas

Attachment: page-title.diff added

Implementation of concept

comment:1 Changed 18 years ago by John Hampton

Resolution: fixed
Status: newclosed

(In [656]) * Now depends on Tags >= 0.3 and < 0.5

  • Wrapped macro output in unicode(x, 'utf-8'), Closes #306
  • Added patch from alect to support using the title in the URL, Closes #313
  • Added patch from coderanger adding a NoFloatFormatter so that the blog won't render macros that support it, like the TocMacro.

comment:2 Changed 18 years ago by John Hampton

For the time being, I don't think we should worry about the case where someone changes the title. There isn't a good method of renaming wikipages in trac and that's what would be required to support that. Also, if a link suddenly changes out from under someone, that'll probably be fairly surprising.

comment:3 Changed 18 years ago by Alec Thomas

Resolution: fixed
Status: closedreopened

Got another patch which fixes one bug and cleans up my patch a bit. The bug occurred when you use something like [[BlogPost(tag=(devtodo,news),pagename="DevTodo/News/%Y-%m-%d-%@",readonly=1, link="Post new news item")]]

The strftime symbols were not being replaced, as substitution only occurred if a pagename was not provided.

The other fixes are truncating pagenames with %@ substitution to 60 characters, as that is the maximum size of the page title, and stripping leading and trailing hyphens (which can occur if you have a title like "I like cheese!!").

  • blog/new_blog.py

     
    114114                                          '%Y/%m/%d/%H.%M')
    115115        wikitext = req.args.get('text', '')
    116116        blogtitle = req.args.get('blogtitle', '')
    117         urltitle = re.sub(r'[^\w]+', '-', blogtitle).lower()
    118         while '-' in urltitle and len(urltitle) > 32:
    119             urltitle = '-'.join(urltitle.split('-')[:-1])
    120         pagename = req.args.get('pagename', time.strftime(pg_name_fmt))
    121         if '%@' in pagename and urltitle:
     117        pagename = req.args.get('pagename', pg_name_fmt)
     118        pagename = time.strftime(pagename)
     119        if '%@' in pagename and blogtitle:
     120            urltitle = re.sub(r'[^\w]+', '-', blogtitle).lower()
    122121            pagename = pagename.replace('%@', urltitle)
     122            while '-' in pagename and len(pagename) > 60:
     123                pagename = '-'.join(pagename.split('-')[:-1])
     124            pagename.strip('-')
    123125        comment = req.args.get('comment', '')
    124126        readonly = int(req.args.has_key('readonly'))
    125127        edit_rows = int(req.args.get('edite_rows', 20))

comment:4 Changed 18 years ago by Alec Thomas

Whoops, stupid.

Index: blog/new_blog.py
===================================================================
--- blog/new_blog.py    (revision 657)
+++ blog/new_blog.py    (working copy)
@@ -114,12 +114,14 @@
                                           '%Y/%m/%d/%H.%M')
         wikitext = req.args.get('text', '')
         blogtitle = req.args.get('blogtitle', '')
-        urltitle = re.sub(r'[^\w]+', '-', blogtitle).lower() 
-        while '-' in urltitle and len(urltitle) > 32: 
-            urltitle = '-'.join(urltitle.split('-')[:-1]) 
-        pagename = req.args.get('pagename', time.strftime(pg_name_fmt)) 
-        if '%@' in pagename and urltitle: 
+        pagename = req.args.get('pagename', pg_name_fmt) 
+        pagename = time.strftime(pagename)
+        if '%@' in pagename and blogtitle: 
+            urltitle = re.sub(r'[^\w]+', '-', blogtitle).lower() 
             pagename = pagename.replace('%@', urltitle) 
+            while '-' in pagename and len(pagename) > 60: 
+                pagename = '-'.join(pagename.split('-')[:-1]) 
+            pagename = pagename.strip('-')
         comment = req.args.get('comment', '')
         readonly = int(req.args.has_key('readonly'))
         edit_rows = int(req.args.get('edite_rows', 20))

(in plain text for ease of copy and pasting)

comment:5 Changed 18 years ago by Alec Thomas

Resolution: fixed
Status: reopenedclosed

Fixed in r658.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain John Hampton.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.