dwyl / dwyl/fields

Create :slug field for unique URLs

Open
#31 0 comments 0 reactions 0 assignees View on GitHub
enhancement good first issue help wanted
Dominant language
Elixir
Stars
87
Forks
12
Avg merge
21h 40m
Merged PRs (30d)
2

Description

**As a `user`** (_content creator_)
I **want** to have a **slug** (_easy to read and relevant_) URL for the content I am publishing
***So that*** any person seeing the URL can immediately infer/deduce the content.

A **`:slug`** is user/SEO friendly path to an item of content.
Instead of using the [`:cid`](https://github.com/dwyl/cid) of the content e.g: `gVSTedHFGBetxyYib9` or a [UUID](https://github.com/dwyl/alog/issues/15) e.g: `f587be12-bdd4-4723-a8db-e0ee2384aea0` which is _useless_ from a both a user's and SEO perspective.

> Good summary: https://yoast.com/slug/ + https://www.wpbeginner.com/glossary/post-slug/

# Todo

Create following specification:

+ [ ] **`:slug`** field (`String`) - the slug will be stored as plaintext. (_no need to encrypt it as it's **`public`**_)
+ [ ] Create a **`Fields.validate_slug`** function that _validates_ the **`:slug`** as containing exclusively URL safe characters: **`abcdefghijklmnopqrstuvwxyz0123456789-_.`**
+ [ ] Invalid `:slug` should return and **Error** which **`autoform`** will display in the frontend.
e.g: "_That **slug** is invalid, **please include only valid characters** to ensure that humans can read/type it_: **`abcdefghijklmnopqrstuvwxyz0123456789-_.`**"
+ [ ] We cannot perform a Database check for the uniqueness of the `:slug` from a `fields` perspective, but this should be done in the Application that is _using_ the `:slug` field to ensure that there are no duplicate/colliding URLs. This should be added to the _documentation_.

Thankfully there is this StackOverflow answer:
https://stackoverflow.com/questions/695438/safe-characters-for-friendly-url
Which gives _most_ of the detail we need: `ALPHA DIGIT "-" / "." / "_" / "~"`
![image](https://user-images.githubusercontent.com/194400/50897884-60076480-1405-11e9-805e-c92c074f9761.png)

_However_ I would _exclude_ the **`~`** ("_tilde_") character,
because it's not immediately findable on some keyboards and a _pain_ on mobile.

Thus the _valid_ characters for a **`:slug`** should be: **`abcdefghijklmnopqrstuvwxyz0123456789-_.`**
Yes, the W3C Spec allows _uppercase_ characters in URLs https://www.w3.org/TR/WD-html40-970708/htmlweb.html as per https://stackoverflow.com/questions/7996919/should-url-be-case-sensitive but how many of the top 100 websites

Ok, Amazon uses case sensitive URLs ... 🙄
e.g: https://www.amazon.com/Zero-One-Notes-Startups-Future/dp/0804139296/
although ... what _really_ matters in an Amazon URL is the "ASIN" (`:id`) of the item ...
this works: https://www.amazon.com/iCan-write-anything-in-this-section/dp/0804139296/
However many ASIN's are all UPPERCASE:
e.g: https://www.amazon.com/Nintendo-Switch/dp/B01MUAGZ49/
_but_ they still _work_ if down-cased: https://www.amazon.com/Nintendo-Switch/dp/b01muagz49 ...
I vote that we make **`slug`** ***lowercase*** for now, and if any _user_ requests that we allow UPPERCASE characters, we can add that _later_.

> **Note**: **`:slug`** is different from `:url` #16 in that `:url` is the ***full*** URL
e.g: https://dwyl.com/home whereas a **`:slug`** is just the part _after_ the domain,
e.g: [`home-healthy-creative-technology-co-living-community`](https://github.com/dwyl/home)
(_that's probably **way** too long for a `:slug`, but you get the idea ..._)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.