slug

Java code/library for generating slugs (for use in pretty URLs)

不羁岁月 提交于 2019-11-28 04:30:48
Web frameworks such as Rails and Django has built-in support for "slugs" which are used to generate readable and SEO-friendly URLs: Slugs in Rails Slugs in Django A slug string typically contains only of the characters a-z , 0-9 and - and can hence be written without URL-escaping (think "foo%20bar"). I'm looking for a Java slug function that given any valid Unicode string will return a slug representation ( a-z , 0-9 and - ). A trivial slug function would be something along the lines of: return input.toLowerCase().replaceAll("[^a-z0-9-]", ""); However, this implementation would not handle

How can I create a SEO friendly dash-delimited url from a string?

拟墨画扇 提交于 2019-11-27 21:18:39
Take a string such as: In C#: How do I add "Quotes" around string in a comma delimited list of strings? and convert it to: in-c-how-do-i-add-quotes-around-string-in-a-comma-delimited-list-of-strings Requirements: Separate each word by a dash and remove all punctuation (taking into account not all words are separated by spaces.) Function takes in a max length, and gets all tokens below that max length. Example: ToSeoFriendly("hello world hello world", 14) returns "hello-world" All words are converted to lower case. On a separate note, should there be a minimum length? Shawn Here is my solution

How to create a unique slug in Django

荒凉一梦 提交于 2019-11-27 20:18:46
问题 I am trying to create a unique slug in Django so that I can access a post via a url like this: http://www.example.com/buy-a-new-bike_Boston-MA-02111_2 The relevant models: class ZipCode(models.Model): zipcode = models.CharField(max_length=5) city = models.CharField(max_length=64) statecode = models.CharField(max_length=32) class Need(models.Model): title = models.CharField(max_length=50) us_zip = models.CharField(max_length=5) slug = ????? def get_city(): zip = ZipCode.objects.get(zipcode

django.db.utils.IntegrityError: UNIQUE constraint failed: rango_category__new.slug

对着背影说爱祢 提交于 2019-11-27 20:16:26
I'm learning Django from Tango with Django but I keep getting this error when I type: python manage.py makemigrations rango python manage.py migrate This is the output: django.db.utils.IntegrityError: UNIQUE constraint failed: rango_category__new.slug Models.py: from django.db import models from django.template.defaultfilters import slugify class Category(models.Model): name = models.CharField(max_length=128, unique=True) views = models.IntegerField(default=0) likes = models.IntegerField(default=0) slug = models.SlugField(unique=True) def save(self, *args, **kwargs): self.slug = slugify(self

Convert non-ASCII characters (umlauts, accents…) to their closest ASCII equivalent (slug creation)

百般思念 提交于 2019-11-27 14:57:58
I am looking for way in JavaScript to convert non- ASCII characters in a string to their closest equivalent, similarly to what the PHP iconv function does. For instance if the input string is Rånades på Skyttis i Ö-vik , it should be converted to Ranades pa skyttis i o-vik . I had a look at phpjs but iconv isn't included. Is it possible to perform such conversion in JavaScript, if so how? Rez The easiest way I've found: var str = "Rånades på Skyttis i Ö-vik"; var combining = /[\u0300-\u036F]/g; console.log(str.normalize('NFKD').replace(combining, '')); For reference see https://developer

Using slugs in codeigniter

倖福魔咒の 提交于 2019-11-27 12:29:39
I have heard of people using slugs for generating clean urls. I have no idea how it works. Currently i have a codeigniter site which generates url's like this www.site.com/index.php/blog/view/7 From what i understand by maintaining a slug field it is possible to achieve urls like www.site.com/index.php/blog/view/once-upon-a-time How is this done? Especially in reference to codeigniter? I just store the slugs in my database table, in a column called slug , then find a post with the slug, like this: public function view($slug) { $query = $this->db->get_where('posts', array('slug' => $slug), 1);

String slugification in Python

偶尔善良 提交于 2019-11-27 11:04:22
I am in search of the best way to "slugify" string what "slug" is , and my current solution is based on this recipe I have changed it a little bit to: s = 'String to slugify' slug = unicodedata.normalize('NFKD', s) slug = slug.encode('ascii', 'ignore').lower() slug = re.sub(r'[^a-z0-9]+', '-', slug).strip('-') slug = re.sub(r'[-]+', '-', slug) Anyone see any problems with this code? It is working fine, but maybe I am missing something or you know a better way? kratenko There is a python package named python-slugify , which does a pretty good job of slugifying: pip install python-slugify Works

Best way to generate slugs (human-readable IDs) in Rails

不羁岁月 提交于 2019-11-27 06:06:34
You know, like myblog.com/posts/donald-e-knuth. Should I do this with the built in parameterize method ? What about a plugin? I could imagine a plugin being nice for handling duplicate slugs, etc. Here are some popular Github plugins -- does anyone have any experience with them? http://github.com/rsl/stringex/tree/master http://github.com/norman/friendly_id/tree/master Basically it seems like slugs are a totally solved problem, and I don't to reinvent the wheel. I use the following, which will translate & --> "and" and @ --> "at" doesn't insert an underscore in place of an apostrophe, so "foo

MVC 4 creating slug type url

天大地大妈咪最大 提交于 2019-11-27 01:42:25
问题 i am trying to create a stackoverflow like url. I the following example works fine. But if i remove the controller then it errors out. http://localhost:12719/Thread/Thread/500/slug-url-text Note the first Thread is the controller the second is the action. How can i make the above URL look like the following excluding the controller name from the url? http://localhost:12719/Thread/500/slug-url-text My Routes public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) {

Slugify and Character Transliteration in C#

余生颓废 提交于 2019-11-27 01:24:10
问题 I'm trying to translate the following slugify method from PHP to C#: http://snipplr.com/view/22741/slugify-a-string-in-php/ Edit: For the sake of convenience, here the code from above: /** * Modifies a string to remove al non ASCII characters and spaces. */ static public function slugify($text) { // replace non letter or digits by - $text = preg_replace('~[^\\pL\d]+~u', '-', $text); // trim $text = trim($text, '-'); // transliterate if (function_exists('iconv')) { $text = iconv('utf-8', 'us