Skip to content

Commit

Permalink
Support md urls redux (#105)
Browse files Browse the repository at this point in the history
* format {S#|P#} display (#80)

to include a description of the trait value

* persist data source branch in localStorage (#89)

* persist data source branch in localStorage

* fix compile build failure

which appears to have been introduced through random dependency
drift, not any changes here :/

* cache cypress binary in CI

to fix https://github.com/pi-base/web/actions/runs/7149095438/job/19470902100?pr=89

* fix trait#show page reactivity (#94)

per report [here](https://github.com/orgs/pi-base/discussions/464#discussioncomment-7560692)

* truncate previews at first line break (#96)

* fix filter reactivity (#97)

fixes #77

* add related trait filter url param

* typeset internal links (#99)

* misc. minor style tweaks (#100)

- adjust icon styling
- fix spacing around ,s in alias lists
- correct table header style

* use action verbs in robot toggle (#103)

* Update homepage to promote code4math (#93)

* Update homepage to promote code4math

* typo, formatting

* formatting

* lint

* redirect to normalized ids

---------

Co-authored-by: Steven Clontz <[email protected]>
  • Loading branch information
jamesdabbs and StevenClontz authored Dec 13, 2023
1 parent 93d6ed8 commit 7e1b389
Show file tree
Hide file tree
Showing 49 changed files with 519 additions and 293 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,17 @@ jobs:
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-v1-${{ hashFiles('**/pnpm-lock.yaml') }}
key: ${{ runner.os }}-pnpm-store-v2-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-v1-
${{ runner.os }}-pnpm-store-v2-
- uses: actions/cache@v3
name: Setup Cypress cache
with:
path: /github/home/.cache/Cypress
key: ${{ runner.os }}-cypress-v1-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-cypress-v1-
- name: Install dependencies
run: pnpm install
Expand All @@ -58,7 +66,7 @@ jobs:
cp cypress/fixtures/main.min.json dist/refs/heads/main.json
- name: Cypress run
uses: cypress-io/github-action@v5
uses: cypress-io/github-action@v6
with:
browser: chrome
build: echo "Start runs build"
Expand Down
7 changes: 4 additions & 3 deletions packages/compile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"scripts": {
"build": "tsc",
"dev": "nodemon",
"start": "ts-node --esm src/watch.ts",
"start": "tsx src/watch.ts",
"test": "vitest run",
"test:cov": "vitest run --coverage",
"test:watch": "vitest"
Expand All @@ -47,6 +47,7 @@
"@types/yaml-front-matter": "^4.1.0",
"cors": "^2.8.5",
"express": "^4.18.2",
"tsheredoc": "^1.0.1"
"tsheredoc": "^1.0.1",
"tsx": "^4.6.2"
}
}
}
20 changes: 8 additions & 12 deletions packages/compile/src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@ const repo = join(__dirname, '..', 'test', 'repo')
const out = join(repo, 'out.json')

async function run(dir: string) {
const { stdout, stderr, error, status } = spawnSync(
'pnpm',
['exec', 'ts-node', '--esm', main],
{
env: {
GITHUB_REF: 'refs/heads/test',
GITHUB_SHA: 'c74d99cf46f6ed23e742f2617e9908294b4a608b',
GITHUB_WORKSPACE: join(repo, dir),
INPUT_OUT: out,
PATH: process.env.PATH,
},
const { stdout, stderr, error, status } = spawnSync('tsx', [main], {
env: {
GITHUB_REF: 'refs/heads/test',
GITHUB_SHA: 'c74d99cf46f6ed23e742f2617e9908294b4a608b',
GITHUB_WORKSPACE: join(repo, dir),
INPUT_OUT: out,
PATH: process.env.PATH,
},
)
})

if (error) {
throw error
Expand Down
26 changes: 13 additions & 13 deletions packages/core/src/Id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ export type Tagged =
| PropertyId
| TheoremId
| { kind: 'trait'; space: number; property: number }
| { kind: 'unknown'; id: number }

export type SpaceId = { kind: 'space'; id: number }
export type PropertyId = { kind: 'property'; id: number }
export type TheoremId = { kind: 'theorem'; id: number }

const pattern = /^(?<prefix>[spti])?0*(?<id>\d+)/i
const pattern = /^(?<prefix>[spti])0*(?<id>\d+)/i

export function traitId({ space, property }: TraitId): string {
return `${space}|${property}`
Expand All @@ -22,9 +21,18 @@ export function format(prefix: string, number: number): string {
return `${prefix}${number.toString().padStart(6, '0')}`
}

export function trim(id: string): string {
export function normalize(id: string) {
const match = pattern.exec(id)
return match?.groups ? match.groups.id : id
if (!match || !match.groups) {
return null
}

return format(match.groups.prefix.toUpperCase(), +match.groups.id)
}

export function trim(id: string): string {
const match = /([1-9]\d*)$/.exec(id)
return match ? match[1] : id
}

export function tag(input: string): Tagged | null {
Expand All @@ -34,9 +42,6 @@ export function tag(input: string): Tagged | null {
}

const id = parseInt(match.groups.id)
if (!match.groups.prefix) {
return { kind: 'unknown', id }
}
switch (match.groups.prefix.toUpperCase()) {
case 'S':
return { kind: 'space', id }
Expand All @@ -51,10 +56,5 @@ export function tag(input: string): Tagged | null {
}

export function toInt(id: string): number {
const tagged = tag(id)
if (tagged === null || tagged.kind === 'trait') {
return 0
} // TODO: return undefined

return tagged.id
return +trim(id)
}
4 changes: 2 additions & 2 deletions packages/core/src/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ export function parser({
.use(remarkRehype)
// Convert math nodes to hast
.use(rehypeKatex)
// Automatically remove outermost paragraph wrapper
.use(unnest)
// Optionally trim mdast to a minimal preview
.use(truncator, {
maxChars: 100,
disable: !truncate,
ignoreTags: ['math', 'inline-math'],
})
// Automatically remove outermost paragraph wrapper
.use(unnest)
// Render hast to HTML string
.use(rehypeStringify)
)
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/Parser/truncate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ export function truncate({

if (node.type === 'text') {
foundText += node.value.length

if (foundText >= maxChars) {
node.value = `${node.value.slice(
0,
node.value.length - (foundText - maxChars),
)}${ellipses}`
return maxChars
} else if (node.value === '\n') {
node.value = ''
return maxChars
}
}

Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/Parser/unnest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { Transformer } from 'unified'
*/
export const unnest = () => {
const transformer: Transformer<Root> = tree => {
if (tree && tree.children?.length === 1 && 'tagName' in tree.children[0]) {
if (tree.children) {
tree.children = tree.children.filter(n => n.type !== 'text' || n.value)
}

if (tree?.children.length === 1 && 'tagName' in tree.children[0]) {
tree.children = tree.children[0].children

if ('tagName' in tree.children[0] && tree.children[0].tagName === 'p') {
Expand Down
36 changes: 29 additions & 7 deletions packages/core/test/Id.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import { format, toInt, trim, tag } from '../src/Id'
import { format, normalize, toInt, trim, tag } from '../src/Id'

describe('format', () => {
it('pads the given character', () => {
Expand All @@ -20,15 +20,37 @@ describe('toInt', () => {
expect(toInt('P12')).toEqual(12)
})

it('does not match nonexistent kinds', () => {
expect(toInt('Z000100')).toEqual(0)
it('handles non-existent kinds', () => {
expect(toInt('Z000100')).toEqual(100)
})

it('matches unknown kind', () => {
expect(toInt('000123')).toEqual(123)
})
})

describe('normalize', () => {
it('pads', () => {
expect(normalize('T100')).toEqual('T000100')
})

it('capitalizes', () => {
expect(normalize('s10')).toEqual('S000010')
})

it('handles leading zeros', () => {
expect(normalize('P012')).toEqual('P000012')
})

it('nulls nonexistent kinds', () => {
expect(normalize('Z00100')).toEqual(null)
})

it('trims file suffixes', () => {
expect(normalize('S000123.md')).toEqual('S000123')
})
})

describe('trim', () => {
it('trims down to the numeric content', () => {
expect(trim('T000100')).toEqual('100')
Expand All @@ -38,8 +60,8 @@ describe('trim', () => {
expect(trim('P12')).toEqual('12')
})

it('returns self for nonexistent kinds', () => {
expect(trim('Z000100')).toEqual('Z000100')
it('handles nonexistent kinds', () => {
expect(trim('Z000100')).toEqual('100')
})

it('matches unknown kind', () => {
Expand All @@ -60,8 +82,8 @@ describe('tag', () => {
expect(tag('T000100')?.kind).toEqual('theorem')
})

it('tags unknowns', () => {
expect(tag('000100')?.kind).toEqual('unknown')
it('is null if missing a kind', () => {
expect(tag('000100')).toEqual(null)
})

it('is null for nonexistent kinds', () => {
Expand Down
35 changes: 34 additions & 1 deletion packages/core/test/Parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ function link([kind, id]: [unknown, unknown]) {
}
}

async function parse(input: string) {
async function parse(input: string, { truncate = false } = {}) {
const file = await parser({
link: {
internal: link,
external: link,
},
truncate,
}).process(input)
return String(file)
}
Expand Down Expand Up @@ -90,6 +91,38 @@ it.todo('expands math in linked titles', async () => {
)
})

describe('truncate', () => {
it('breaks on newlines', () => {
const input = `a first sentence.\n\nand some extra stuff`
expect(parse(input)).resolves.toEqual(
'<p>a first sentence.</p>\n<p>and some extra stuff</p>',
)
expect(parse(input, { truncate: true })).resolves.toEqual(
'a first sentence.',
)
})

it('adds ellipses', () => {
expect(
parse(
'this is a fairly long sentence and it needs to be summarized because it is too long because it just goes on and on and on',
{ truncate: true },
),
).resolves.toEqual(
'this is a fairly long sentence and it needs to be summarized because it is too long because it just …',
)
})

it('preserves math', () => {
expect(
parse(
'this is a fairly long sentence and it needs to be summarized because it is too long because it $T_{3\\frac{1}{2}}$ just goes on and on and on',
{ truncate: true },
),
).resolves.toMatchSnapshot()
})
})

describe('unwrapping', () => {
it('unwraps math', () => {
expect(parse('$\\sigma$')).resolves.toEqual(
Expand Down
2 changes: 2 additions & 0 deletions packages/core/test/__snapshots__/Parser.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ exports[`parses a complex example 1`] = `
<li><a href=\\"mo://123\\" title=\\"123\\" class=\\"external-link\\">123</a></li>
</ul>"
`;
exports[`truncate > preserves math 1`] = `"this is a fairly long sentence and it needs to be summarized because it is too long because it <span class=\\"math math-inline\\"><span class=\\"katex\\"><span class=\\"katex-mathml\\"><math xmlns=\\"http://www.w3.org/1998/Math/MathML\\"><semantics><mrow><msub><mi>T</mi><mrow><mn>3</mn><mfrac><mn>1</mn><mn>2</mn></mfrac></mrow></msub></mrow><annotation encoding=\\"application/x-tex\\">T_{3\\\\frac{1}{2}}</annotation></semantics></math></span><span class=\\"katex-html\\" aria-hidden=\\"true\\"><span class=\\"base\\"><span class=\\"strut\\" style=\\"height:1.1704em;vertical-align:-0.487em;\\"></span><span class=\\"mord\\"><span class=\\"mord mathnormal\\" style=\\"margin-right:0.13889em;\\">T</span><span class=\\"msupsub\\"><span class=\\"vlist-t vlist-t2\\"><span class=\\"vlist-r\\"><span class=\\"vlist\\" style=\\"height:0.3448em;\\"><span style=\\"top:-2.7538em;margin-left:-0.1389em;margin-right:0.05em;\\"><span class=\\"pstrut\\" style=\\"height:3em;\\"></span><span class=\\"sizing reset-size6 size3 mtight\\"><span class=\\"mord mtight\\"><span class=\\"mord mtight\\">3</span><span class=\\"mord mtight\\"><span class=\\"mopen nulldelimiter sizing reset-size3 size6\\"></span><span class=\\"mfrac\\"><span class=\\"vlist-t vlist-t2\\"><span class=\\"vlist-r\\"><span class=\\"vlist\\" style=\\"height:0.8443em;\\"><span style=\\"top:-2.656em;\\"><span class=\\"pstrut\\" style=\\"height:3em;\\"></span><span class=\\"sizing reset-size3 size1 mtight\\"><span class=\\"mord mtight\\"><span class=\\"mord mtight\\">2</span></span></span></span><span style=\\"top:-3.2255em;\\"><span class=\\"pstrut\\" style=\\"height:3em;\\"></span><span class=\\"frac-line mtight\\" style=\\"border-bottom-width:0.049em;\\"></span></span><span style=\\"top:-3.384em;\\"><span class=\\"pstrut\\" style=\\"height:3em;\\"></span><span class=\\"sizing reset-size3 size1 mtight\\"><span class=\\"mord mtight\\"><span class=\\"mord mtight\\">1</span></span></span></span></span><span class=\\"vlist-s\\">​…</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>"`;
8 changes: 4 additions & 4 deletions packages/core/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export default defineConfig({
},
test: {
coverage: {
lines: 91.19,
branches: 94.07,
statements: 91.19,
functions: 84.21,
lines: 93.19,
branches: 94.37,
statements: 93.19,
functions: 85.06,
skipFull: true,
thresholdAutoUpdate: true,
exclude: ['src/Formula/Grammar.ts', 'test'],
Expand Down
4 changes: 3 additions & 1 deletion packages/viewer/cypress/e2e/typesetting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ it('renders internal links', () => {
)

cy.get('[data-testid=output]').contains(
'Discrete topology on a two-point set is $T_0$ as noted in Discrete topology on a two-point set | $T_0$',
// The T0T_0T0 rendering here is the text representation of the inner html of katex rendered math.
// We're effectively asserting that it _isn't_ still rendered as $T_0$
'Discrete topology on a two-point set is T0T_0T0​ as noted in Discrete topology on a two-point set is T0T_0T0​',
)
})
26 changes: 12 additions & 14 deletions packages/viewer/src/components/Home.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,20 @@
<a href="https://clontz.org">Steven Clontz</a>
joined the project in 2017.
</p>
<h3>Other Mathematical Databases</h3>
<h3>Community</h3>
<p>
Integer sequences: <a href="https://oeis.org/">OEIS</a> | L-functions and
modular forms: <a href="https://www.lmfdb.org/citation">LMFDB</a> | Rings
and modules: <a href="https://ringtheory.herokuapp.com/">DaRT</a> | Graphs:
<a href="https://houseofgraphs.org/">HoG</a>
The π-Base is part of the
<a href="https://code4math.org" style="font-family:monospace">code4math</a>
community. Join the conversation on either the
<a href="https://code4math.zulipchat.com/">code4math Zulip</a>
or the
<a href="https://github.com/orgs/pi-base/discussions">
π-Base GitHub Discussion board</a
>.
</p>
<p>
And many more:
<a href="https://mathdb.mathhub.info/">Catalogue of Mathematical Datasets</a
>
</p>
<p>
The π-Base software was designed to support any category of
objects/properties/theorems. If you're interested in adapting π-Base for use
in your field, reach out to us on GitHub.
More databases may be discovered at the
<a href="https://mathbases.org/">Index of Mathematical DataBases</a>.
</p>
<h3>Special Acknowledgements</h3>
<p>
Expand Down Expand Up @@ -115,7 +113,7 @@
Funding from the <a href="https://www.southalabama.edu/"
>University of South Alabama</a
>
Faculty Development Council (2017-2018).
Faculty Development Council from 2017-2018.
</li>
</ul>
</main>
Expand Down
Loading

0 comments on commit 7e1b389

Please sign in to comment.