From 28b8b922ee9d31f0880949e4b76ba2cd0298c053 Mon Sep 17 00:00:00 2001 From: george-hub331 Date: Sun, 9 Mar 2025 15:41:36 +0100 Subject: [PATCH 1/2] feat: add reusable component for consistent documentation links --- src/components/ExplorePage.tsx | 3 +- src/components/cid-info/CidInfo.tsx | 16 +++---- src/components/common/DocLink.stories.tsx | 46 ++++++++++++++++++++ src/components/common/DocLink.tsx | 52 +++++++++++++++++++++++ src/components/object-info/ObjectInfo.tsx | 3 +- 5 files changed, 109 insertions(+), 11 deletions(-) create mode 100644 src/components/common/DocLink.stories.tsx create mode 100644 src/components/common/DocLink.tsx diff --git a/src/components/ExplorePage.tsx b/src/components/ExplorePage.tsx index 9985f873..a4578d08 100644 --- a/src/components/ExplorePage.tsx +++ b/src/components/ExplorePage.tsx @@ -45,7 +45,8 @@ export const ExplorePage = ({ } return ( -
+ //
+
{t('ExplorePage.title')} diff --git a/src/components/cid-info/CidInfo.tsx b/src/components/cid-info/CidInfo.tsx index 0d906736..8c500abb 100644 --- a/src/components/cid-info/CidInfo.tsx +++ b/src/components/cid-info/CidInfo.tsx @@ -1,6 +1,7 @@ import React, { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import extractInfo, { type ExtractedInfo } from '../../lib/extract-info.js' +import { DocLink } from '../common/DocLink' export interface CidInfoProps extends React.HTMLAttributes { cid: string | null @@ -31,9 +32,9 @@ export const CidInfo: React.FC = ({ cid, className, ...props }) => return (
{(cidInfo == null) ? null @@ -48,12 +49,9 @@ export const CidInfo: React.FC = ({ cid, className, ...props }) => - + {t('multihash')} - +
0x @@ -68,10 +66,10 @@ export const CidInfo: React.FC = ({ cid, className, ...props }) => {t('CidInfo.hashDigest')}
- + 0x {cidInfo.hashFnCode} = {cidInfo.hashFn} - +
0x {cidInfo.hashLengthCode} = {cidInfo.hashLengthInBits} bits diff --git a/src/components/common/DocLink.stories.tsx b/src/components/common/DocLink.stories.tsx new file mode 100644 index 00000000..7b61d873 --- /dev/null +++ b/src/components/common/DocLink.stories.tsx @@ -0,0 +1,46 @@ +import React from 'react' +import { DocLink } from './DocLink' +import type { Meta, StoryObj } from '@storybook/react' + +const meta: Meta = { + title: 'Common/DocLink', + component: DocLink, + args: { + term: 'cid', + className: 'ma2' + } +} + +export default meta +type Story = StoryObj + +export const Default: Story = { + args: { + term: 'cid' + } +} + +export const WithCustomText: Story = { + args: { + term: 'cid', + children: 'Content Identifier' + } +} + +export const WithCustomPath: Story = { + args: { + term: 'cid', + glossaryPath: 'concepts/content-addressing' + } +} + +export const MultipleLinks: Story = { + render: () => ( +
+ CID + Multibase + Multicodec + Multihash +
+ ) +} diff --git a/src/components/common/DocLink.tsx b/src/components/common/DocLink.tsx new file mode 100644 index 00000000..4b8644bf --- /dev/null +++ b/src/components/common/DocLink.tsx @@ -0,0 +1,52 @@ +import React from 'react' +import { useTranslation } from 'react-i18next' + +export interface DocLinkProps extends React.AnchorHTMLAttributes { + term: string + glossaryPath?: string + children?: React.ReactNode +} + +/** + * A component for rendering documentation links. + * Links to the IPFS documentation glossary by default. + */ +export const DocLink: React.FC = ({ + term, + glossaryPath = 'concepts/glossary', + children, + className = '', + ...props +}) => { + const { t } = useTranslation('explore') + const baseUrl = 'https://docs.ipfs.io' + const href = `${baseUrl}/${glossaryPath}/#${term.toLowerCase()}` + + return ( + + {children ?? term} + + + + + ) +} + +export default DocLink diff --git a/src/components/object-info/ObjectInfo.tsx b/src/components/object-info/ObjectInfo.tsx index 54e3a2a0..22e86aa9 100644 --- a/src/components/object-info/ObjectInfo.tsx +++ b/src/components/object-info/ObjectInfo.tsx @@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next' import { ObjectInspector, chromeLight } from 'react-inspector' import getCodecNameFromCode from '../../lib/get-codec-name-from-code' import { type NormalizedDagNode, type UnixFsNodeDataWithNumbers } from '../../types.js' +import { DocLink } from '../common/DocLink.js' import LargeLinksTable, { type LinkObject, type LargeLinksTableProps } from './links-table' const humansize = partial({ round: 0 }) @@ -138,7 +139,7 @@ export const ObjectInfo: React.FC = ({ className, type, cid, lo {format === 'unixfs' ? ( - UnixFS + UnixFS ) : null} {isUnixFs From 188150fb7a74476363f5d87fc3cd05c196715c27 Mon Sep 17 00:00:00 2001 From: george-hub331 Date: Wed, 12 Mar 2025 03:09:10 +0100 Subject: [PATCH 2/2] feat: add documentation link translation --- public/locales/en/explore.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/public/locales/en/explore.json b/public/locales/en/explore.json index b6422f5d..86c790f9 100644 --- a/public/locales/en/explore.json +++ b/public/locales/en/explore.json @@ -70,5 +70,8 @@ }, "errors": { "BlockFetchTimeoutError": "Failed to fetch content in {timeout}s. Please refresh the page to retry or try a different CID." + }, + "docLinks": { + "viewInDocs": "View in IPFS Documentation" } }