Skip to content

Commit

Permalink
fix: improve & fix pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
jrson83 committed Jul 12, 2024
1 parent 1d2b69b commit 13ec17e
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports.biome": "explicit"
"source.organizeImports": "explicit"
},
"files.insertFinalNewline": true,
"deno.enable": true,
Expand Down
12 changes: 6 additions & 6 deletions _config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import { config } from './_build.ts'

import lume from 'lume/mod.ts'
import date from 'lume/plugins/date.ts'
import slugify_urls from 'lume/plugins/slugify_urls.ts'
import inline from 'lume/plugins/inline.ts'
import jsx from 'lume/plugins/jsx_preact.ts'
import unified from 'lume/plugins/remark.ts'
import sass from 'lume/plugins/sass.ts'
import terser from 'lume/plugins/terser.ts'
import inline from 'lume/plugins/inline.ts'
import sitemap from 'lume/plugins/sitemap.ts'
import unified from 'lume/plugins/remark.ts'
import slugify_urls from 'lume/plugins/slugify_urls.ts'
import terser from 'lume/plugins/terser.ts'

import remarkPlugins from '#plugins/unified/remark/mod.ts'
import rehypePlugins from '#plugins/unified/rehype/mod.ts'
import atomFeed from '#plugins/atom-feed/mod.ts'
import md5CacheBuster from '#plugins/md5-cache-buster/mod.ts'
import rehypePlugins from '#plugins/unified/rehype/mod.ts'
import remarkPlugins from '#plugins/unified/remark/mod.ts'

const site = lume({
location: config.location,
Expand Down
2 changes: 1 addition & 1 deletion plugins/_deprecated/sitemap/mod.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// deno-lint-ignore-file -- The plugin is deprecated in favour of: https://lume.land/plugins/sitemap/

import { merge } from 'lume/core/utils.ts'
import { Page } from 'lume/core/filesystem.ts'
import { buildSort } from 'lume/core/searcher.ts'
import { merge } from 'lume/core/utils.ts'

import type { Site } from 'lume/core.ts'
import type { Search } from 'lume/plugins/search.ts'
Expand Down
4 changes: 2 additions & 2 deletions plugins/atom-feed/mod.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { merge } from 'lume/core/utils.ts'
import { Page } from 'lume/core/filesystem.ts'
import { buildSort } from 'lume/core/searcher.ts'
import { merge } from 'lume/core/utils.ts'

import { isString } from '#utils'

import { XMLFormat } from '#plugins/atom-feed/deps.ts'

import type { Site } from 'lume/core.ts'
import type { Search } from 'lume/plugins/search.ts'
import type { MetaData } from 'lume/plugins/metas.ts'
import type { Search } from 'lume/plugins/search.ts'

export interface Options {
/** The query to search pages included in the feed. defaults to `type=post` */
Expand Down
4 changes: 2 additions & 2 deletions plugins/md5-cache-buster/mod.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Md5 } from './deps.ts'
import { merge } from 'lume/core/utils.ts'
import modifyUrls from 'lume/plugins/modify_urls.ts'
import { Md5 } from './deps.ts'

import type { Message } from './deps.ts'
import type { Page, Site } from 'lume/core.ts'
import type { Message } from './deps.ts'

export interface Options {
/** The list of extensions this plugin applies to */
Expand Down
12 changes: 6 additions & 6 deletions plugins/unified/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ export * as unified from 'npm:[email protected]'

export { default as readingTime } from 'https://esm.sh/[email protected]?bundle'

export { default as rehypeMinifyWhitespace } from 'npm:rehype-[email protected].0'
export { default as rehypeExtractToc } from 'npm:@stefanprobst/rehype-[email protected].0'
export { default as rehypeCodeTitles } from 'npm:[email protected]'
export { default as rehypeExternalLinks } from 'npm:[email protected]'
export { default as rehypeExtractToc } from 'npm:@stefanprobst/[email protected]'
export { default as rehypePrismPlus } from 'npm:[email protected]'
export { default as rehypeMinifyWhitespace } from 'npm:[email protected]'
export { default as rehypePrismDiff } from 'npm:[email protected]'
export { default as rehypePrismPlus } from 'npm:[email protected]'

export { slug } from 'npm:[email protected]'
export { toString } from 'npm:[email protected]'
export { findAfter } from 'npm:[email protected]'
export { CONTINUE, EXIT, SKIP, visit } from 'npm:[email protected]'
export { toString } from 'npm:[email protected]'

export { default as rehypeImgSize } from 'npm:[email protected]'
export type { Test } from 'npm:[email protected]'
export { default as rehypeCopyCode } from './rehype/rehypeCopyCode.ts'
export { default as rehypeSlugAnchorSectionize } from './rehype/slug.ts'
export type { Test } from 'npm:[email protected]'
export { default as rehypeImgSize } from 'npm:[email protected]'
2 changes: 1 addition & 1 deletion plugins/unified/rehype/mod.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { dirname, fromFileUrl } from 'https://deno.land/[email protected]/path/mod.ts'
import {
rehypeCodeTitles,
rehypeCopyCode,
Expand All @@ -9,7 +10,6 @@ import {
rehypePrismPlus,
rehypeSlugAnchorSectionize,
} from '../deps.ts'
import { dirname, fromFileUrl } from 'https://deno.land/[email protected]/path/mod.ts'

const __dirname = dirname(fromFileUrl(import.meta.url))

Expand Down
2 changes: 1 addition & 1 deletion plugins/unified/rehype/rehypeCopyCode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Element, Root } from 'npm:@types/[email protected]'
import { unified, visit } from '#plugins/unified/deps.ts'
import type { Element, Root } from 'npm:@types/[email protected]'

const rehypeCopyCode: unified.Plugin<[], Root> = () => {
return (tree: Root) => {
Expand Down
2 changes: 1 addition & 1 deletion plugins/unified/rehype/slug.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Element, Root } from 'npm:@types/[email protected]'
import {
findAfter,
slug,
Expand All @@ -6,7 +7,6 @@ import {
unified,
visit,
} from '../deps.ts'
import type { Element, Root } from 'npm:@types/[email protected]'

export interface RehypeSlugAnchorSectionizeOptions {
/** The heading level depth to sectionize. defaults to `3` */
Expand Down
2 changes: 1 addition & 1 deletion scripts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ScriptsConfiguration } from 'https://deno.land/x/[email protected]/mod.ts'
import type { ScriptsConfiguration } from 'https://deno.land/x/[email protected]/mod.ts'

export default <ScriptsConfiguration> {
scripts: {
Expand Down
2 changes: 1 addition & 1 deletion src/404.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const title = '404: Page Not Found'
export const layout = 'layouts/root.tsx'
export const url = '/404/'

export default (data: PageData, { urlFilter }: PageHelpers) => {
export default (_data: PageData, { urlFilter }: PageHelpers) => {
return (
<>
<h1>{title}</h1>
Expand Down
38 changes: 22 additions & 16 deletions src/_components/blog/pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { PageData, PageHelpers } from '#types'

import { getPaginationPages } from '#utils'

export default (
Expand Down Expand Up @@ -42,21 +41,28 @@ export default (
&nbsp;Prev
</li>
)}
{getPaginationPages(pagination?.totalPages!, pagination?.page!).map((
index,
) => (
<li key={index}>
<a
href={urlFilter!(`/blog${index > 1 && `/${index}` || ``}`)}
className={`pagination__item ${
pagination?.page === index ? 'is-active' : ''
}`}
{...(pagination?.page === index && { ariaCurrent: true })}
>
{index}
</a>
</li>
))}
{pagination &&
getPaginationPages(pagination.totalPages, pagination.page).map((
pageNumber,
idx,
) => {
const isNumber = !isNaN(pageNumber)
const isActive = pagination?.page === pageNumber

return (
<li key={idx}>
<a
{...(isActive && { ariaCurrent: true })}
{...(!isNumber
? { role: 'link', 'aria-disabled': true }
: { href: urlFilter!(`/blog/${pageNumber}`) })}
className={`pagination__item ${isActive ? 'is-active' : ''}`}
>
{isNumber ? pageNumber : '...'}
</a>
</li>
)
})}
{pagination?.next
? (
<li>
Expand Down
7 changes: 6 additions & 1 deletion src/_includes/scss/components/_pagination.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
display: flex;
align-items: center;
padding: 0.125rem 0.5rem;


&[aria-disabled="true"] {
pointer-events: none;
cursor: default;
}

&.is-active {
border: map.get($pagination, active-border);
border-radius: map.get($pagination, active-border-radius);
Expand Down
8 changes: 4 additions & 4 deletions src/_includes/utils/getPaginationPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
export function getPaginationPages(
maxPages: number,
currentPage: number,
): Array<number | string> {
const pages: Array<number | string> = []
): number[] {
const pages: number[] = []

for (let i = 1; i <= maxPages; i++) {
if (
Expand All @@ -13,8 +13,8 @@ export function getPaginationPages(
(maxPages - currentPage < 3 && maxPages - i <= 3)
) {
pages.push(i)
} else if (pages[pages.length - 1] !== '...') {
pages.push('...')
} else if (!isNaN(pages[pages.length - 1])) {
pages.push(NaN)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/_includes/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './capitalize.ts'
export * from './getPaginationPages.ts'
export * from './isEmptyArray.ts'
export * from './truncateString.ts'
export * from './isString.ts'
export * from './truncateString.ts'

0 comments on commit 13ec17e

Please sign in to comment.