from markupsafe import Markup
import re
_punct_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+')
#from unidecode import unidecode # if you are OK with non-ASCII
symbols, comment this out, else install unidecode library
unidecode_func = lambda s: s # if you set this to unidecode, non-ASCII
symbols will be slugified into ASCII
# e.g. unidecode("北亰") == "Bei Jing "
str_func = unicode if sys.version_info < (3,) else str
def custom_create_slug(title, delim='-'):
# Get rid of any html entities
slug = Markup(title).unescape()
result = []
for word in _punct_re.split(slug):
result.extend(unidecode_func(word).split())
slug = str_func(delim.join(result)).lower()
return slug
blog.post.slugify = custom_create_slug
also, i had to modify _controllers/blog/post.py/create_permalink() so
it now uses config.slugify, if exists (it must be a bug).
works with both posts and categories.
btw, i didn't find any bugtracker on github, am i missing something?
On Mon, May 28, 2012 at 6:38 AM, Wasil Sergejczyk <szelga....@gmail.com> wrote:
> _config.py:
> from markupsafe import Markup
> import re
> _punct_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+')
> #from unidecode import unidecode # if you are OK with non-ASCII
> symbols, comment this out, else install unidecode library
> unidecode_func = lambda s: s # if you set this to unidecode, non-ASCII
> symbols will be slugified into ASCII
> # e.g. unidecode("北亰") == "Bei Jing "
> str_func = unicode if sys.version_info < (3,) else str
> def custom_create_slug(title, delim='-'):
> # Get rid of any html entities
> slug = Markup(title).unescape()
> result = []
> for word in _punct_re.split(slug):
> result.extend(unidecode_func(word).split())
> slug = str_func(delim.join(result)).lower()
> return slug
> blog.post.slugify = custom_create_slug
You're right that Unicode handling in slug creation is not what it
should be. I think this snippet could be worked into the create_slug()
function in blogofile_blog/site_src/_controllers/blog/post.py
I'd welcome a pull request for that.
> also, i had to modify _controllers/blog/post.py/create_permalink() so
> it now uses config.slugify, if exists (it must be a bug).
> works with both posts and categories.
I'm pretty sure that if you make the change in create_slug() it will
flow through to permalink pages and categories too.
> You're right that Unicode handling in slug creation is not what it
> should be. I think this snippet could be worked into the create_slug()
> function in blogofile_blog/site_src/_controllers/blog/post.py
> I'd welcome a pull request for that.
as soon as i learn git a little bit, which will be slowed down by RL-
stuff.
> > also, i had to modify _controllers/blog/post.py/create_permalink() so
> > it now uses config.slugify, if exists (it must be a bug).
> > works with both posts and categories.
> I'm pretty sure that if you make the change in create_slug() it will
> flow through to permalink pages and categories too.
of course, but blog.post.slugify setting doesn't work as intended (at
least, it doesn't affect path).
> as soon as i learn git a little bit, which will be slowed down by RL-
> stuff.
also, i'd like to add slugging for categories and avoiding doubling of
categories' names and posts' paths first.
in order to implement the latter feature i should keep track of Post
and Category instances. i'm planning to do it like this:
http://stackoverflow.com/questions/328851/python-printing-all-instanc... (see "Use a mixin and weakrefs" section). is that OK?
ok, nevermind my pull request. i think, slugging would be better moved into blogofile core, because other plugins (there isn't any, but i can think of a couple and definitely will be making them after this) might want to use that too. so, will i redo this?
On Thu, May 31, 2012 at 12:36 AM, Wasil Sergejczyk <szelga....@gmail.com> wrote:
> ok, nevermind my pull request. i think, slugging would be better moved into
> blogofile core, because other plugins (there isn't any, but i can think of a
> couple and definitely will be making them after this) might want to use that
> too. so, will i redo this?
Don't be too hasty to abandon that pull request!
I'm not sure where you are thinking about putting the slugify code in
blogofile core, but don't plan on it going anywhere under site_init/.
If the work I'm doing now on refactoring the `blogofile init` command
goes as I hope site_init/ should disappear from blogofile core.
Anything that we want to keep from there should go into one or more
plugins.
I can understand that if you see multiple uses for the slugify code
among plugins, you don't want to repeat it. I just don't know right
now what the right mechanism is to facilitate that.
> On Thu, May 31, 2012 at 12:36 AM, Wasil Sergejczyk <szelga....@gmail.com>
> wrote:
> > ok, nevermind my pull request. i think, slugging would be better moved
> into
> > blogofile core, because other plugins (there isn't any, but i can think
> of a
> > couple and definitely will be making them after this) might want to use
> that
> > too. so, will i redo this?
> Don't be too hasty to abandon that pull request!
> I'm not sure where you are thinking about putting the slugify code in
> blogofile core, but don't plan on it going anywhere under site_init/.
> If the work I'm doing now on refactoring the `blogofile init` command
> goes as I hope site_init/ should disappear from blogofile core.
> Anything that we want to keep from there should go into one or more
> plugins.
> I can understand that if you see multiple uses for the slugify code
> among plugins, you don't want to repeat it. I just don't know right
> now what the right mechanism is to facilitate that.
> --
> You received this message because you are subscribed to the Google Groups
> "blogofile-discuss" group.
> To post to this group, send email to blogofile-discuss@googlegroups.com.
> To unsubscribe from this group, send email to
> blogofile-discuss+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/blogofile-discuss?hl=en.
> i thought something like that: in plugin you can write, say,
> from blogofile.tools import create_slug
> but the exact place is yours to decide.
> 2012/5/31 Doug Latornell <d...@douglatornell.ca>
> On Thu, May 31, 2012 at 12:36 AM, Wasil Sergejczyk <szelga....@gmail.com> wrote:
> > ok, nevermind my pull request. i think, slugging would be better moved into
> > blogofile core, because other plugins (there isn't any, but i can think of a
> > couple and definitely will be making them after this) might want to use that
> > too. so, will i redo this?
> Don't be too hasty to abandon that pull request!
> I'm not sure where you are thinking about putting the slugify code in
> blogofile core, but don't plan on it going anywhere under site_init/.
> If the work I'm doing now on refactoring the `blogofile init` command
> goes as I hope site_init/ should disappear from blogofile core.
> Anything that we want to keep from there should go into one or more
> plugins.
> I can understand that if you see multiple uses for the slugify code
> among plugins, you don't want to repeat it. I just don't know right
> now what the right mechanism is to facilitate that.
> --
> You received this message because you are subscribed to the Google Groups "blogofile-discuss" group.
> To post to this group, send email to blogofile-discuss@googlegroups.com.
> To unsubscribe from this group, send email to blogofile-discuss+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/blogofile-discuss?hl=en.
> -- > Best regards.
> -- > You received this message because you are subscribed to the Google Groups "blogofile-discuss" group.
> To post to this group, send email to blogofile-discuss@googlegroups.com.
> To unsubscribe from this group, send email to blogofile-discuss+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/blogofile-discuss?hl=en.
On Thu, May 31, 2012 at 10:32 AM, Wasil Sergejczyk <szelga....@gmail.com> wrote:
> i thought something like that: in plugin you can write, say,
> from blogofile.tools import create_slug
> but the exact place is yours to decide.
Yeah, okay, that works for me.
We already have a "junk drawer" (as Mike calls it) - blogofile.util.
So, I guess that's where create_slug() should go.
I'd prefer to call it blogfile.tools, but I don't think we need util
and tools. And I don't have a good sense yet for what kind of
backwards compatibility mess would result from moving the non-junk
from util into tools.
>> On Thu, May 31, 2012 at 12:36 AM, Wasil Sergejczyk <szelga....@gmail.com>
>> wrote:
>> > ok, nevermind my pull request. i think, slugging would be better moved
>> > into
>> > blogofile core, because other plugins (there isn't any, but i can think
>> > of a
>> > couple and definitely will be making them after this) might want to use
>> > that
>> > too. so, will i redo this?
>> Don't be too hasty to abandon that pull request!
>> I'm not sure where you are thinking about putting the slugify code in
>> blogofile core, but don't plan on it going anywhere under site_init/.
>> If the work I'm doing now on refactoring the `blogofile init` command
>> goes as I hope site_init/ should disappear from blogofile core.
>> Anything that we want to keep from there should go into one or more
>> plugins.
>> I can understand that if you see multiple uses for the slugify code
>> among plugins, you don't want to repeat it. I just don't know right
>> now what the right mechanism is to facilitate that.
>> --
>> You received this message because you are subscribed to the Google Groups
>> "blogofile-discuss" group.
>> To post to this group, send email to blogofile-discuss@googlegroups.com.
>> To unsubscribe from this group, send email to
>> blogofile-discuss+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/blogofile-discuss?hl=en.
> --
> Best regards.
> --
> You received this message because you are subscribed to the Google Groups
> "blogofile-discuss" group.
> To post to this group, send email to blogofile-discuss@googlegroups.com.
> To unsubscribe from this group, send email to
> blogofile-discuss+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/blogofile-discuss?hl=en.
> On Thu, May 31, 2012 at 10:32 AM, Wasil Sergejczyk <szelga....@gmail.com> > wrote: > > i thought something like that: in plugin you can write, say, > > from blogofile.tools import create_slug > > but the exact place is yours to decide.
> Yeah, okay, that works for me.
> We already have a "junk drawer" (as Mike calls it) - blogofile.util. > So, I guess that's where create_slug() should go.
> I'd prefer to call it blogfile.tools, but I don't think we need util > and tools. And I don't have a good sense yet for what kind of > backwards compatibility mess would result from moving the non-junk > from util into tools.
> >> On Thu, May 31, 2012 at 12:36 AM, Wasil Sergejczyk <
> szelga....@gmail.com> > >> wrote: > >> > ok, nevermind my pull request. i think, slugging would be better > moved > >> > into > >> > blogofile core, because other plugins (there isn't any, but i can > think > >> > of a > >> > couple and definitely will be making them after this) might want to > use > >> > that > >> > too. so, will i redo this?
> >> Don't be too hasty to abandon that pull request!
> >> I'm not sure where you are thinking about putting the slugify code in > >> blogofile core, but don't plan on it going anywhere under site_init/. > >> If the work I'm doing now on refactoring the `blogofile init` command > >> goes as I hope site_init/ should disappear from blogofile core. > >> Anything that we want to keep from there should go into one or more > >> plugins.
> >> I can understand that if you see multiple uses for the slugify code > >> among plugins, you don't want to repeat it. I just don't know right > >> now what the right mechanism is to facilitate that.
> >> -- > >> You received this message because you are subscribed to the Google > Groups > >> "blogofile-discuss" group. > >> To post to this group, send email to blogofile-discuss@googlegroups.com.
> > -- > > You received this message because you are subscribed to the Google > Groups > > "blogofile-discuss" group. > > To post to this group, send email to blogofile-discuss@googlegroups.com.
> On Thu, May 31, 2012 at 10:32 AM, Wasil Sergejczyk <szelga....@gmail.com> > wrote: > > i thought something like that: in plugin you can write, say, > > from blogofile.tools import create_slug > > but the exact place is yours to decide.
> Yeah, okay, that works for me.
> We already have a "junk drawer" (as Mike calls it) - blogofile.util. > So, I guess that's where create_slug() should go.
> I'd prefer to call it blogfile.tools, but I don't think we need util > and tools. And I don't have a good sense yet for what kind of > backwards compatibility mess would result from moving the non-junk > from util into tools.
> >> On Thu, May 31, 2012 at 12:36 AM, Wasil Sergejczyk <
> szelga....@gmail.com> > >> wrote: > >> > ok, nevermind my pull request. i think, slugging would be better > moved > >> > into > >> > blogofile core, because other plugins (there isn't any, but i can > think > >> > of a > >> > couple and definitely will be making them after this) might want to > use > >> > that > >> > too. so, will i redo this?
> >> Don't be too hasty to abandon that pull request!
> >> I'm not sure where you are thinking about putting the slugify code in > >> blogofile core, but don't plan on it going anywhere under site_init/. > >> If the work I'm doing now on refactoring the `blogofile init` command > >> goes as I hope site_init/ should disappear from blogofile core. > >> Anything that we want to keep from there should go into one or more > >> plugins.
> >> I can understand that if you see multiple uses for the slugify code > >> among plugins, you don't want to repeat it. I just don't know right > >> now what the right mechanism is to facilitate that.
> >> -- > >> You received this message because you are subscribed to the Google > Groups > >> "blogofile-discuss" group. > >> To post to this group, send email to blogofile-discuss@googlegroups.com.
> > -- > > You received this message because you are subscribed to the Google > Groups > > "blogofile-discuss" group. > > To post to this group, send email to blogofile-discuss@googlegroups.com.
> On Thu, May 31, 2012 at 10:32 AM, Wasil Sergejczyk <szelga....@gmail.com> > wrote: > > i thought something like that: in plugin you can write, say, > > from blogofile.tools import create_slug > > but the exact place is yours to decide.
> Yeah, okay, that works for me.
> We already have a "junk drawer" (as Mike calls it) - blogofile.util. > So, I guess that's where create_slug() should go.
> I'd prefer to call it blogfile.tools, but I don't think we need util > and tools. And I don't have a good sense yet for what kind of > backwards compatibility mess would result from moving the non-junk > from util into tools.
> >> On Thu, May 31, 2012 at 12:36 AM, Wasil Sergejczyk <
> szelga....@gmail.com> > >> wrote: > >> > ok, nevermind my pull request. i think, slugging would be better > moved > >> > into > >> > blogofile core, because other plugins (there isn't any, but i can > think > >> > of a > >> > couple and definitely will be making them after this) might want to > use > >> > that > >> > too. so, will i redo this?
> >> Don't be too hasty to abandon that pull request!
> >> I'm not sure where you are thinking about putting the slugify code in > >> blogofile core, but don't plan on it going anywhere under site_init/. > >> If the work I'm doing now on refactoring the `blogofile init` command > >> goes as I hope site_init/ should disappear from blogofile core. > >> Anything that we want to keep from there should go into one or more > >> plugins.
> >> I can understand that if you see multiple uses for the slugify code > >> among plugins, you don't want to repeat it. I just don't know right > >> now what the right mechanism is to facilitate that.
> >> -- > >> You received this message because you are subscribed to the Google > Groups > >> "blogofile-discuss" group. > >> To post to this group, send email to blogofile-discuss@googlegroups.com.
> > -- > > You received this message because you are subscribed to the Google > Groups > > "blogofile-discuss" group. > > To post to this group, send email to blogofile-discuss@googlegroups.com.
> On Thu, May 31, 2012 at 10:32 AM, Wasil Sergejczyk <szelga....@gmail.com> > wrote: > > i thought something like that: in plugin you can write, say, > > from blogofile.tools import create_slug > > but the exact place is yours to decide.
> Yeah, okay, that works for me.
> We already have a "junk drawer" (as Mike calls it) -
On Sat, Jun 16, 2012 at 11:14 PM, Wasil Sergejczyk <szelga....@gmail.com> wrote:
> i'm very sorry, but better late, than never. anyway, here are two pull
> requests from me on github.
> To post to this group, send email to blogofile-discuss@googlegroups.com.
> To unsubscribe from this group, send email to
> blogofile-discuss+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/blogofile-discuss?hl=en.