Modify

Opened 9 years ago

Closed 9 years ago

Last modified 4 years ago

#313 closed enhancement (fixed)

Blog "title" in the URL

Reported by: athomas Owned by: pacopablo
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 athomas 9 years ago.
Implementation of concept

Download all attachments as: .zip

Change History (6)

Changed 9 years ago by athomas

Implementation of concept

comment:1 Changed 9 years ago by pacopablo

  • Resolution set to fixed
  • Status changed from new to closed

(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 9 years ago by pacopablo

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 9 years ago by athomas

  • Resolution fixed deleted
  • Status changed from closed to reopened

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 9 years ago by athomas

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 9 years ago by athomas

  • Resolution set to fixed
  • Status changed from reopened to closed

Fixed in r658.

Add Comment

Modify Ticket

Action
as closed The owner will remain pacopablo.
The resolution will be deleted. Next status will be 'reopened'.
Author


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

 
Note: See TracTickets for help on using tickets.