slug

Should I create a slug on the fly or store in DB?

冷暖自知 提交于 2019-11-29 23:13:32
A slug is part of a URL that describes or titles a page and is usually keyword rich for that page improving SEO. e.g. In this URL PHP/JS - Create thumbnails on the fly or store as files that last section "php-js-create-thumbnails-on-the-fly-or-store-as-files" is the slug. Currently I am storing the slug for each page with the page's record in the DB. The slug is generated from the Title field when the page is generated and stored with the page. However, I'm considering generating the slug on the fly in case I want to change it. I'm trying to work out which is better and what others have done.

Fetching records with slug instead of ID

非 Y 不嫁゛ 提交于 2019-11-29 20:25:39
问题 I'm currently trying to find the best way (in term of usability and performance) when dealing with a situation like fetching records tagged with a specific tag, or category, or something like that. A good way (the way I wanted to do), would be to fetch records with the tag/category slug, so the URL would look like : http://stackoverflow.com/questions/tagged/language-agnostic fetching records by slug, which looks better than : http://stackoverflow.com/questions/tag/789/language-agnostic

parse URL with JavaScript or jQuery

落爺英雄遲暮 提交于 2019-11-29 04:47:38
Ok lets say I have a URL example.com/hello/world/20111020 (with or without the trailing slash). What I would like to do is strip from the url the domain example.com. and then break the hello world 20111020 into an array. But my other problem is. Sometimes the URL has no /hello/world/20111020 or just /hello/ so I need to first determine if there is anything after example.com if there not, then do nothing as obviously there's nothing to work with. However if there is something there for each / I need to add it to this array in order. So I can work with the array[0] and know it was hello. I tried

ID + Slug name in URL in Rails (like in StackOverflow)

元气小坏坏 提交于 2019-11-28 22:50:14
问题 I'm trying to achieve URLs like this in Rails: http://localhost/posts/1234/post-slug-name with both ID and slug name instead of either http://localhost/posts/1234 or http://localhost/posts/post-slug-name (right now I have just slug name in URL, so this part is over). How can I do this? UPD I found an article on this: http://augustl.com/blog/2009/styling_rails_urls/, instead of /id/slug it suggests to use /id-slug which works perfectly for me, so I'll go with this. 回答1: You'll want to add a

Django Url, Slug for Detail Page

a 夏天 提交于 2019-11-28 20:50:41
I'm having trouble configuring my url to display a detail view. Clicking on this link: <a href='{% url blog_detail blog.slug %}'>{{ blog.name }}</a> shows blog.html , when I thought it would show blog-detail.html . There are no errors and the browser bar says: example.com/blog/the-slug , yet still displays the html from blog.html , not blog-detail.html . Any ideas why? Thanks for your ideas. url: url(r'^blog/', 'myapp.views.blog', name='blog'), url(r'^blog/(?P<slug>[\w-]+)/$', 'myapp.views.blog_detail', name='blog_detail'), views: def blog(request): blog_list = Blog.objects.all() return render

How to create a unique slug in Django

自闭症网瘾萝莉.ら 提交于 2019-11-28 18:21:47
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=self.us_zip) city = "%s, %s %s" % (zip.city, zip.statecode, zip.zipcode) return city A sample ZipCode

Why SlugField() in Django?

三世轮回 提交于 2019-11-28 18:10:15
Django has models.SlugField() which helps us to create some cool looking urls. My question is why specifying it as a field suppose I have this model class Blog(models.Model): title = models.CharField() and if I want to add slug, I could just use class Blog(models.Model): title = models.CharField() def title_slug(self): return slugify(self.title) in urls I could just use (r'^blog/(?P<id>\d+)/(?P<slug>[-\w]+)/$', 'app.views.blog_view'), and in views def blog_view(request, id ,slug): get_object_or_404(Blog, pk=id) ... urls will look like example.com/blog/23/why-iam-here/ There are three things

Using slugs in laravel 5?

孤者浪人 提交于 2019-11-28 09:29:16
I have made eloquent-sluggable work on my app. Slugs are saved just fine. Buuuut... How do I use it to create a pretty url? If possible, I would like to use them in my url instead of ID numbers. Yes, you can use slug in your route and generated url , for example, if you declare a route something like this: Route::get('users/{username}', 'UserController@profile')->where('profile', '[a-z]+'); Then in your controller, you may declare the method like this: public function profile($username) { $user = User::where('username', $username)->first(); } The username is your slug here and it must be a

MVC 4 creating slug type url

我怕爱的太早我们不能终老 提交于 2019-11-28 07:05:05
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) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute("Default", // Route name "

Slugify and Character Transliteration in C#

落爺英雄遲暮 提交于 2019-11-28 06:33:36
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-ascii//TRANSLIT', $text); } // lowercase $text = strtolower($text); // remove unwanted characters $text