CenterForDigitalHumanities / CenterForDigitalHumanities/rerum_server_nodejs
Helper functions for slug processing
- Dominant language
- JavaScript
- Stars
- 3
- Forks
- 6
- Avg merge
- 1h 25m
- Merged PRs (30d)
- 3
Description
In support of #151, the following transforming library for slugs should be added:
1. `getSlugFromMetadata(__rerum:Object)` -> `validSlug:String`
- extract `"this-slug"` from DB record property `{__rerum: { slug : "this-slug" } }`
- throw invalid argument if not `__rerum` metadata
- return empty `""` if `slug` property empty or missing
3. `assignSlug(slug:String, document:Object)` -> `document:Object`
- insert or overwrite `"this-slug"` to `__rerum` property for traditional save
- empty/remove slug with empty `""`
4. `findBySlug(slug:String)` async -> `document:Object`
- RERUM lookup for slug match
- 404 on a miss, 400 on a bad slug
6. `transferSlug(toDocument:Object, fromDocument?:Object)` async -> `200 `
- RERUM upsert toDocument with `"this-slug"` and RERUM patch fromDocument with `{ __rerum.slug: "" }`
- A single transaction, revert on a failure
7. `slugExists(slug:String)` async -> `Boolean`
- *findBySlug(slug) is not 40x
9. `slugIsValid(slug:String)` -> `Boolean`
- slug and normalizeSlug(slug) match
10. `normalizeSlug(userSlug:String)` -> `validSlug:String`
- "This, That & the Other! Various Outré Considerations" -> "this-that-the-other-various-outre-considerations"
11. `buildSluggedId(validSlug:String)` -> `atIdUrl:Url`
- "this-slug" -> "https://store.rerum.io/v1/id/this-slug"
Only "normalizeSlug" takes user input.
Contributor guide
Assessment
This issue has not been assessed yet.