oletemCode
12/31/2017 - 4:23 PM

Slug_creator

Some systems define a slug as the part of a URL that identifies a page in human-readable keywords.[4][5] It is usually the end part of the URL, which can be interpreted as the name of the resource, similar to the basename in a filename or the title of a page. The name is based on the use of the word slug in the news media to indicate a short name given to an article for internal use.

Slugs are typically generated automatically from a page title but can also be entered or altered manually, so that while the page title remains designed for display and human readability, its slug may be optimized for brevity or for consumption by search engines. Long page titles may also be truncated to keep the final URL to a reasonable length.

Slugs are generally entirely lowercase, with accented characters replaced by letters from the English alphabet and whitespace characters replaced by a dash or an underscore to avoid being encoded. Punctuation marks are generally removed, and some also remove short, common words such as conjunctions. For example:

Original title: This, That and the Other! An Outré Collection Generated slug: this-that-other-outre-collection

function createSlug(str){
  return str.split(" ").reduce(function(prev, next){//Чтобы reduce работал нужно подогнать стринг к еррею
    return prev.concat([next.toLowerCase()])//Добавляй к предыдущему следущее в ловеркейсе;
  }, [])
  .join("-");
}

createSlug( "Leo Finally Wins a Freaking Oscar!");

"leo-finally-wins-a-freaking-oscar!"