diff --git a/README.md b/README.md index 8ca3f3b..fe568f9 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ const { | Function | Description | Parameters | Returns | | | --------------------------------------------------- | -------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | -------- | | `topAuthors(limit?)` | Fetches authors sorted by total views | `limit` (number, default `10`): number of authors to return (1–50) | `Author[]` | | -| `authorPosts(name, limit?, sort?)` | Retrieves published posts by a given author | `name` (string): display name and profile ID (e.g., "jane-doe-123")
`limit` (number, default `10`)
`sort` ("newest" | "most\_viewed", default "newest") | `Post[]` | +| `authorPosts(tag, limit?, sort?)` | Retrieves published posts by a given author | `tag` (string): display name and profile ID (e.g., "jane-doe-123")
`limit` (number, default `10`)
`sort` ("newest" | "most\_viewed", default "newest") | `Post[]` | | `getTags(limit?)` | Returns tags with their associated post counts | `limit` (number, default `20`): number of tags (1–100) | `Tag[]` | | | `explore(search?, page?, limit?, sort?, tag?)` | Paginated list of articles with filtering and sorting | `search` (string)
`page` (number, default `1`)
`limit` (number, default `12`)
`sort` ("recommended" | | | | "newest" | | | | | diff --git a/package.json b/package.json index 7045d0b..fbf79a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@persian-caesar/hycom-api", - "version": "1.1.1", + "version": "1.1.2", "description": "A package for easy using hycom.ir api service.", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -33,4 +33,4 @@ "devDependencies": { "@types/node": "^22.15.21" } -} +} \ No newline at end of file diff --git a/src/HyCom.ts b/src/HyCom.ts index 767255a..c8327e9 100644 --- a/src/HyCom.ts +++ b/src/HyCom.ts @@ -190,7 +190,10 @@ async function topAuthors(limit: number = 10) { const response = await fetch(hycom.url + hycom.topAuthor + `?limit=${limit}`); const data: TopAuthorResponse = await response.json(); - return data.data; + return data.data.map(a => { + a.tag = a.display_name + "-" + a.profile_id + return a; + }); } catch { return null; } @@ -199,13 +202,13 @@ async function topAuthors(limit: number = 10) { /** * Returns published posts by a specific author. * - * @param display_name Author display name and profile ID. (format: name-code) + * @param tag Author display name and profile ID. (format: name-code) * @param limit Number of authors to return. (1-50) * @param sort Sort order. (newest, most_viewed) */ -async function authorPosts(display_name: string, limit: number = 10, sort: SortParametr = "newest") { +async function authorPosts(tag: string, limit: number = 10, sort: SortParametr = "newest") { try { - const response = await fetch(hycom.url + hycom.authorPosts + `/${display_name}?limit=${limit}&sort=${sort}`); + const response = await fetch(hycom.url + hycom.authorPosts + `/${tag}?limit=${limit}&sort=${sort}`); const data: AuthorPostsResponse = await response.json(); return data.data; diff --git a/src/types.ts b/src/types.ts index 6575149..6dc2c5d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -2,6 +2,7 @@ export type SortParametr = "newest" | "most_viewed"; export type ExploreSortParametr = "recommended" | SortParametr; export interface Author { + tag: string; display_name: string; profile_id: string; url: string; diff --git a/tsconfig.json b/tsconfig.json index 0bc1542..2e7559f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,7 @@ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ /* Language and Environment */ - "target": "ES2024", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + "target": "ES2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ // "jsx": "preserve", /* Specify what JSX code is generated. */ // "libReplacement": true, /* Enable lib replacement. */