#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)
Change History (6)
Changed 19 years ago by
Attachment: | page-title.diff added |
---|
comment:1 Changed 19 years ago by
Resolution: | → fixed |
---|---|
Status: | new → 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 19 years ago by
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 19 years ago by
Resolution: | fixed |
---|---|
Status: | closed → 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
114 114 '%Y/%m/%d/%H.%M') 115 115 wikitext = req.args.get('text', '') 116 116 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() 122 121 pagename = pagename.replace('%@', urltitle) 122 while '-' in pagename and len(pagename) > 60: 123 pagename = '-'.join(pagename.split('-')[:-1]) 124 pagename.strip('-') 123 125 comment = req.args.get('comment', '') 124 126 readonly = int(req.args.has_key('readonly')) 125 127 edit_rows = int(req.args.get('edite_rows', 20))
comment:4 Changed 19 years ago by
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)
Implementation of concept