Skip to content

Commit

Permalink
Merge pull request #6 from jill64/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jill64 committed Sep 13, 2023
2 parents 7befc85 + 6031779 commit cf10b3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jill64/svelte-pagination",
"version": "0.1.0",
"version": "0.1.1",
"type": "module",
"description": "Pagination component for Svelte",
"main": "dist/index.js",
Expand Down
16 changes: 13 additions & 3 deletions src/lib/Paginate.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,24 @@
$: remainLeft = clamp(current - 1, 0, last - 1)
$: remainRight = clamp(last - current, 0, last - 1)
$: baseDepth = base.match(/\//g)?.length ?? 0
$: pathArray = $page.url.pathname.split('/')
$: replaceIndex = routeId
? routeId.split('/').indexOf(slug) + baseDepth
: null
$: makeHref = (target: number) => {
if (!routeId) {
if (!replaceIndex) {
return ''
}
const pathname = routeId.replace(slug, target.toString())
const pathname = [
...pathArray.slice(0, replaceIndex),
target.toString(),
...pathArray.slice(replaceIndex + 1)
].join('/')
return `${base}${pathname}${$page.url.search}${$page.url.hash}`
return `${pathname}${$page.url.search}${$page.url.hash}`
}
</script>

Expand Down

0 comments on commit cf10b3b

Please sign in to comment.