Skip to content

Commit

Permalink
Updating documentatio for all packages
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkalachev committed Nov 28, 2024
1 parent 139565d commit ee11f72
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 13 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
# Weresk Libraries

Toolkit for bulding website with Next.js, Sanity and Tailwind

# Packages

- **`@weresk/core`**: Common utilities and types for the rest of @weresk libraries
- [Documentation](https://github.com/alexanderkalachev/weresk/blob/main/packages/%40weresk/core/README.md)
- **`@weresk/locales`**: Toolkit for Next.js app localization
- [Documentation](https://github.com/alexanderkalachev/weresk/blob/main/packages/%40weresk/locales/README.md)
- **`@weresk/links`**: Toolkit for working with links in Next.js app
- [Documentation](https://github.com/alexanderkalachev/weresk/blob/main/packages/%40weresk/router/README.md)
- **`@weresk/maket`**: Toolkit for working with grid, typography and swatches in TailwindCSS
- [Documentation](https://github.com/alexanderkalachev/weresk/blob/main/packages/%40weresk/maket/README.md)
6 changes: 6 additions & 0 deletions packages/@weresk/locales/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @weresk/locales

## 0.0.5

### Patch Changes

- Updating a documentation

## 0.0.4

### Patch Changes
Expand Down
16 changes: 12 additions & 4 deletions packages/@weresk/locales/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ Toolkit for Next.js app localization
- **`languages: {id: string, title: string}[]`**: List of languages
- **Returns**: **`ReturnType<typeof defineType>[]`**

## Constants

- **`ISO_LOCALES`**: Array of language codes from ISO 639

## Types

- **`LocaleProps<T extends object, Locale extends string | undefined = string | undefined>`**: Adds `lang` property to a props interface
- **`LocaleString<Locale extends string = string>`**: Localized string object
- **`LocaleObject<T extends any, Locale extends string = string>`**: Localized any type object
- **`LocalizationConfig<Locale extends string = string>`**: Localization config definition
- **`IsoLocale`**: Type literal string with language codes from ISO 639
- **`LocaleProps<T extends object, Locale extends string = IsoLocale>`**: Adds optional `lang` property to a props interface
- **`LocaleString<Locale extends string = IsoLocale> = Partial<Record<Locale, string>>`**: Localized string object
- **`LocaleObject<T extends any, Locale extends string = IsoLocale>`**: Localized any type object
- **`LocalizationConfig<Locale extends string = IsoLocale>`**: Localization config definition
- **`languages: {id: Locale; title: string; abbr: string;}[]`**: List of languages
- **`defaultLocale: Locale`**: ID of a default language
- **`safeReplace?: boolean`**: Sets if a default locale should be used if a desired language value is missing

## Utils

Expand Down
2 changes: 1 addition & 1 deletion packages/@weresk/locales/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@weresk/locales",
"version": "0.0.4",
"version": "0.0.5",
"private": false,
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
8 changes: 8 additions & 0 deletions packages/@weresk/maket/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @weresk/maket

## 0.2.6

### Patch Changes

- Updating documentation
- Updated dependencies
- @weresk/locales@0.0.5

## 0.2.5

### Patch Changes
Expand Down
1 change: 1 addition & 0 deletions packages/@weresk/maket/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
**@weresk/maket**
Toolkit for working with grid, typography and swatches in TailwindCSS

# Config Documentation

Expand Down
2 changes: 1 addition & 1 deletion packages/@weresk/maket/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@weresk/maket",
"version": "0.2.5",
"version": "0.2.6",
"private": false,
"exports": {
".": {
Expand Down
6 changes: 6 additions & 0 deletions packages/@weresk/router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @weresk/router

## 0.0.3

### Patch Changes

- Adding documentation

## 0.0.2

### Patch Changes
Expand Down
51 changes: 50 additions & 1 deletion packages/@weresk/router/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,53 @@
**@weresk/router**
Toolkit for working with links in Next.js app

---
# Exports

## Types

- **Schemas**
- **`linkTyped({router: RouterConfig, localization?: LocalizationConfig})`**: Link with manual selection between link types: reference, anchor, external, internal or file
- **`linkExternal({router: RouterConfig, localization?: LocalizationConfig})`**: Link with a caption and external URL
- **`linkCaptioned({router: RouterConfig, localization?: LocalizationConfig})`**: Link with a caption and typed link
- **`linkContact({router: RouterConfig, localization?: LocalizationConfig})`**: Typed contact link
- **`normalizedSlug({router: RouterConfig, localization?: LocalizationConfig})`**: Slug schema with slugify and isUnique functions set
- **`routerObjects({router: RouterConfig, localization?: LocalizationConfig})`**: Generates an array of schema definitions with all types listed above

## Types

- **Props**
- **`ReferenceDocument`**: Base Sanity document type with title, slug and optional parent
- **`RouterSchemaProps`**: Props for router schemas definition
- **`RouterConfig<DocumentType extends ReferenceDocument = ReferenceDocument>`**: Router config object
- `mode: "parent" | "folder"`: Defines what strategy is used for pages structure:
- `parent`: Documents are nested under the parent document like `/parents-parent/parent/slug`
- `folder`: Documents are grouped inside the folder determined by document type, using `routes` configuration, like `/folder/slug`
- `schemas: string[]`: Link of document schemas that can be referenced in links
- `routes: Record<DocumentType["_type"], string>`: Object with document types as keys and folder names as values to use in `folder` mode
- `contacts?: ContactType[]`: Optional customization of contacts types for `linkContact` schema
- `parentDepth?: number`: Optional customization of nesting depth limit used in `parent` mode

## Utils

- **`getDocumentPath(doc: ReferenceDocument | undefined, config: RouterConfig): string`**: Generates URL for a document
- **`getLinkType(url: string): LinkType`**: Checks the link type for a URL
- **`getTypesWithSameRoute(docType: string | undefined, routes: Record<string, string>): string[]`**: Finds the documents types that have the route similar to a singular document type
- **`isUniqueSlugFunction(config: RouterConfig): (slug: string, context: SlugValidationContext) => Promise<boolean>`**: Generates isUniqueSlug function based on router config
- **`normalizeLink(input: string): string`**: Normalizes a string to be used as a URL
- **`prepareLink(input: LinkTyped, router: RouterConfig, lang?: IsoLocale): string`**: Generates an URL from a `LinkTyped` object
- **`wrapReference(doc: ReferenceDocument): LinkTyped`**: Converts a document type into `LinkTyped`

## Components

- **`LinkWrapper`**: A wrapper function to render a Next.js link from router schemas like typed link, reference and href
- **Props: `LinkWrapperProps extends LocaleProps<DefaultPropsWithChildren>`**
- **`href?: string`**: URL, is set used first
- **`reference?: ReferenceDocument`**: Refefence to a document, if set used before the `link`
- **`link?: LinkTyped`**: Typed link
- **`title?: string`**: `title` property for rendered HTML element
- **`config: RouterConfig`**: Router configuration
- **`ContactLink`**: Renders contact link as a text or as an icon
- **Props: `ContactLinkProps extends LocaleProps<DefaultProps>`**
- **`link: LinkContact`**: Contact type identifier
- **`mode: "text" | "icon"`**: Render mode
- **`config: RouterConfig`**: Router configuration
2 changes: 1 addition & 1 deletion packages/@weresk/router/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@weresk/router",
"version": "0.0.2",
"version": "0.0.3",
"private": false,
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
10 changes: 5 additions & 5 deletions packages/@weresk/router/src/utils/getLinkType.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { LinkType } from "../schemas";

export function getLinkType(input: string): LinkType {
if (input.startsWith("#")) {
export function getLinkType(url: string): LinkType {
if (url.startsWith("#")) {
return "anchor";
}
if (
input.startsWith("http://") ||
input.startsWith("https://") ||
input.startsWith("mailto:" || input.startsWith("www."))
url.startsWith("http://") ||
url.startsWith("https://") ||
url.startsWith("mailto:" || url.startsWith("www."))
) {
return "external";
}
Expand Down

0 comments on commit ee11f72

Please sign in to comment.