Skip to content

Commit

Permalink
add custom icon arxiv; NamedIcon that selects built-in or local icons…
Browse files Browse the repository at this point in the history
… based on name
  • Loading branch information
akollegger committed Jan 10, 2025
1 parent 8a4f679 commit 46018ad
Show file tree
Hide file tree
Showing 8 changed files with 2,532 additions and 2,042 deletions.
4,364 changes: 2,371 additions & 1,993 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
"test": "vitest"
},
"dependencies": {
"@astrojs/check": "^0.9.3",
"@astrojs/starlight": "^0.26.1",
"@astrojs/starlight-tailwind": "^2.0.3",
"@astrojs/tailwind": "^5.1.2",
"@effect/platform-node": "^0.65.0",
"astro": "^4.14.5",
"@astrojs/check": "^0.9.4",
"@astrojs/starlight": "^0.30.5",
"@astrojs/starlight-tailwind": "^3.0.0",
"@astrojs/tailwind": "^5.1.4",
"@effect/platform-node": "^0.68.1",
"astro": "^5.1.4",
"date-fns": "^4.1.0",
"effect": "^3.11.0",
"effect": "^3.12.1",
"sharp": "^0.33.5",
"tailwindcss": "^3.4.15",
"typescript": "^5.5.4",
"vitest": "^2.1.7",
"tailwindcss": "^3.4.17",
"typescript": "^5.7.3",
"vitest": "^2.1.8",
"xml-js": "^1.6.11"
}
}
46 changes: 7 additions & 39 deletions src/components/GrArxivPage.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { format } from 'date-fns';

import {extractArxivID, getPaper} from '../lib/arxiv'

import LinkSpan from './LinkSpan.astro'

import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
import { Icon } from '@astrojs/starlight/components';

const props = Astro.props;

Expand All @@ -18,21 +21,21 @@ const paper = getPaper(arxivid)
<StarlightPage
frontmatter={{ title: arxivEntry.title, editUrl:false, tableOfContents:false} }}
>
<p class="byline text-xs">
<p class="byline text-sm">
<time itemprop="published" datetime={format(arxivEntry.published, 'yyyy-MM-dd')}>
Published {format(arxivEntry.published, 'MMMM do, yyyy')}
</time>
<address class="author text-xs">By
<address class="author text-sm">By
{arxivEntry.author.map( (author:any, i:number) => (
<span>{(i ? ', ' : '')}<a rel="author" class="url fn n">{author.name}</a></span>
))}
</address>
<cite class="arxivid text-xs">
<cite class="arxivid text-sm">
<a href={arxivEntry.id}>arXiv:{arxivid}</a>
[ {arxivEntry.category.join(", ")}
]
</cite>
<cite class="github text-xs">
<cite class="github text-sm">
{paper?.github !== undefined && paper.github !== "" ?
(<a href={"https://github.com/" + paper?.github}>github:{paper?.github}</a>)
: ''
Expand All @@ -45,38 +48,3 @@ const paper = getPaper(arxivid)
<blockquote><p>{arxivEntry.summary}</p></blockquote>

</StarlightPage>



<!-- <StarlightPage
frontmatter={{ title: `${entry.title.text}`, editUrl:false, tableOfContents:false} }}
>
<p class="byline text-xs">
<time pubdate={format(pubDate, 'yyyy-MM-dd')} title="August 28th, 2011">Published {format(pubDate, 'MMMM do, yyyy')}</time>
<address class="author text-xs">By
{authors.map( (author:any, i:number) => (
<span key={i}>{(i ? ', ' : '')}
<a rel="author" class="url fn n">{author.name.text}</a>
</span>
))}
</address>
<cite class="arxivid text-xs">
<a href={entry.id.text}>arXiv:{arxivid}</a>
[ {categories.map( (category:any) => category._attributes.term).join(", ")}
]
</cite>
<cite class="github text-xs">
{paper?.github !== undefined && paper.github !== "" ?
(<a href={"https://github.com/" + paper?.github}>github:{paper?.github}</a>)
: ''
}
</cite>
</p>
<h2 id="quote">Abstract</h2>
<blockquote><p>{entry.summary.text}</p></blockquote>
</StarlightPage> -->
33 changes: 33 additions & 0 deletions src/components/GrIcon.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
import { LocalIcons } from './LocalIcons';
interface Props {
name: keyof typeof LocalIcons;
label?: string;
color?: string;
size?: string;
class?: string;
}
const { name, label, size = '1em', color } = Astro.props;
const a11yAttrs = label ? ({ 'aria-label': label } as const) : ({ 'aria-hidden': 'true' } as const);
---

<svg
{...a11yAttrs}
class={Astro.props.class}
width="16"
height="16"
viewBox="0 0 24 24"
fill="currentColor"
set:html={LocalIcons[name]}
/>

<style define:vars={{ 'sl-icon-color': color, 'sl-icon-size': size }}>
svg {
color: var(--sl-icon-color);
font-size: var(--sl-icon-size, 1em);
width: 1em;
height: 1em;
}
</style>
76 changes: 76 additions & 0 deletions src/components/LinkSpan.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
import type { HTMLAttributes } from 'astro/types';
import NamedIcon, { type IconNames } from './NamedIcon.astro';
interface Props extends Omit<HTMLAttributes<'a'>, 'href'> {
href: string | URL;
icon?: IconNames | undefined;
iconPlacement?: 'start' | 'end' | undefined;
variant?: 'primary' | 'secondary' | 'minimal';
}
const {
class: className,
icon,
iconPlacement = 'start',
variant = 'primary',
...attrs
} = Astro.props;
---

<a class:list={['gr-link-span not-content', variant, className]} {...attrs}>

{icon && iconPlacement === 'start' && <NamedIcon size="2.0rem" name={icon}/>}
<slot />
{icon && iconPlacement === 'end' && <NamedIcon size="2.0rem" name={icon}/>}
</a>

<style>
.gr-link-span {
align-items: center;
border: 1px solid transparent;
display: inline-flex;
font-size: var(--sl-text-sm);
gap: 0.5em;
line-height: 1.1875;
outline-offset: 0.25rem;
padding: 0.4375rem 1.125rem;
text-decoration: none;
}

.gr-link-span.primary {
background: var(--sl-color-text-accent);
border-color: var(--sl-color-text-accent);
color: var(--sl-color-black);
}
.gr-link-span.primary:hover {
color: var(--sl-color-black);
}
.gr-link-span.secondary {
border-color: inherit;
color: var(--sl-color-white);
}
.gr-link-span.minimal {
color: var(--sl-color-white);
padding-inline: 0;
}

.gr-link-span :global(svg) {
flex-shrink: 0;
}

@media (min-width: 50rem) {
.gr-link-span {
font-size: var(--sl-text-base);
padding: 0.9375rem 1.25rem;
}
}

:global(.sl-markdown-content) .gr-link-span {
margin-inline-end: 1rem;
}
:global(.sl-markdown-content) .gr-link-span:not(:where(p *)) {
margin-block: 1rem;
}
</style>
6 changes: 6 additions & 0 deletions src/components/LocalIcons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

export const LocalIcons = {
'arxiv':
`<path d="M3.8423 0a1.0037 1.0037 0 0 0 -0.922 0.6078c-0.1536 0.3687 -0.0438 0.6275 0.2938 1.1113l6.9185 8.3597 -1.0223 1.1058a1.0393 1.0393 0 0 0 0.003 1.4229l1.2292 1.3135 -5.4391 6.4444c-0.2803 0.299 -0.4538 0.823 -0.2971 1.1986a1.0253 1.0253 0 0 0 0.9585 0.635 0.9133 0.9133 0 0 0 0.6891 -0.3405l5.783 -6.126 7.4902 8.0051a0.8527 0.8527 0 0 0 0.6835 0.2597 0.9575 0.9575 0 0 0 0.8777 -0.6138c0.1577 -0.377 -0.017 -0.7502 -0.306 -1.1407l-7.0518 -8.3418 1.0632 -1.13a0.9626 0.9626 0 0 0 0.0089 -1.3165L4.6336 0.4639s-0.3733 -0.4535 -0.768 -0.463zm0 0.272h0.0166c0.2179 0.0052 0.4874 0.2715 0.5644 0.3639l0.005 0.006 0.0052 0.0055 10.169 10.9905a0.6915 0.6915 0 0 1 -0.0072 0.945l-1.0666 1.133 -1.4982 -1.7724 -8.5994 -10.39c-0.3286 -0.472 -0.352 -0.6183 -0.2592 -0.841a0.7307 0.7307 0 0 1 0.6704 -0.4401Zm14.341 1.5701a0.877 0.877 0 0 0 -0.6554 0.2418l-5.6962 6.1584 1.6944 1.8319 5.3089 -6.5138c0.3251 -0.4335 0.479 -0.6603 0.3247 -1.0292a1.1205 1.1205 0 0 0 -0.9763 -0.689zm-7.6557 12.2823 1.3186 1.4135 -5.7864 6.1295a0.6494 0.6494 0 0 1 -0.4959 0.26 0.7516 0.7516 0 0 1 -0.706 -0.4669c-0.1119 -0.2682 0.0359 -0.6864 0.2442 -0.9083l0.0051 -0.0055 0.0047 -0.0055z" fill="#000000" stroke-width="1"></path>`
};

25 changes: 25 additions & 0 deletions src/components/NamedIcon.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
import { Icon as SlIcon } from '@astrojs/starlight/components'
import GrIcon from './GrIcon.astro'
import { LocalIcons } from './LocalIcons';
const localIconNames = Object.keys(LocalIcons)
type IconParams = Parameters<typeof SlIcon>
type SlIconNames = IconParams[0]['name']
type LocalIconNames = keyof typeof LocalIcons
export type IconNames = LocalIconNames | SlIconNames
interface Props {
name: IconNames;
label?: string;
color?: string;
size?: string;
class?: string;
}
const { name, label, size = '1em', color } = Astro.props;
const a11yAttrs = label ? ({ 'aria-label': label } as const) : ({ 'aria-hidden': 'true' } as const);
---

{localIconNames.includes(name) ? (<GrIcon name={name as LocalIconNames} />) : (<SlIcon name={name as SlIconNames}/>)}
4 changes: 4 additions & 0 deletions src/data/papers.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,9 @@
{
"arxivid": "2410.19494",
"github": ""
},
{
"arxivid": "2501.00309",
"github": "https://github.com/Graph-RAG/GraphRAG/"
}
]

0 comments on commit 46018ad

Please sign in to comment.