Skip to content

Commit a693684

Browse files
committed
UPDATE: library routes and a few sample entries
1 parent 1bd95f5 commit a693684

File tree

13 files changed

+191
-27
lines changed

13 files changed

+191
-27
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ ENV NODE_ENV=production
3030

3131
USER nonroot
3232
COPY --chown=nonroot:nonroot --from=base /usr/bin/dumb-init /usr/bin/dumb-init
33+
COPY --chown=nonroot:nonroot --from=builder /app/library /app/library
3334
COPY --chown=nonroot:nonroot --from=builder /app/build /app/build
3435
COPY --chown=nonroot:nonroot --from=builder /app/node_modules /app/node_modules
3536
COPY --chown=nonroot:nonroot ./server.js /app/server.js

README.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
[![build](https://github.com/regexplanet/regex-zone/actions/workflows/gcr-deploy.yaml/badge.svg)](https://github.com/regexplanet/regex-zone/actions/workflows/gcr-deploy.yaml)
44

5-
A catalog of useful regular expressions and related resources.
5+
A library of useful regular expressions and related resources.
66

77
## License
88

9-
CC BY-SA 4.0: [Overview](https://creativecommons.org/licenses/by-sa/4.0/), [legal text](LICENSE.txt)
9+
CC BY-SA 4.0: [Overview](https://creativecommons.org/licenses/by-sa/4.0/), [Full text](LICENSE.txt)
1010

1111
## Contributing
1212

@@ -15,6 +15,7 @@ LATER
1515
## Links
1616

1717
- [Wikipedia:Regular_Expression](https://en.wikipedia.org/wiki/Regular_expression)
18+
- [Cheatography Cheat Sheet](https://cheatography.com/davechild/cheat-sheets/regular-expressions/)
1819

1920
## Other Libraries of Regex Patterns
2021

@@ -41,16 +42,3 @@ LATER
4142
[![Remix](https://www.vectorlogo.zone/logos/remix/remix-ar21.svg)](https://remix.run/ "React Framework")
4243
[![TypeScript](https://www.vectorlogo.zone/logos/typescriptlang/typescriptlang-ar21.svg)](https://www.typescriptlang.org/ "Programming Language")
4344
[![Vite](https://www.vectorlogo.zone/logos/vitejsdev/vitejsdev-ar21.svg)](https://vitejs.dev/ "Bundler")
44-
45-
## Font
46-
47-
- Roboto Slab
48-
- OpenSans for body
49-
- Nimbus Mono for code
50-
51-
- Jetbrains mono
52-
- roboto mono
53-
- b612-mono
54-
- DM Mono
55-
- Courier Prime
56-

TODO.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@
1616
- [ ] more regex in the catalog
1717
- [ ] post to places besides RXP
1818
- [ ] 404 page
19+
20+
## Fonts
21+
22+
- Roboto Slab for headings
23+
- OpenSans for body
24+
- Nimbus Mono for code

app/components/HeaderSearch/HeaderSearch.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Autocomplete, Group, Burger, rem, Anchor } from '@mantine/core';
22
import { useDisclosure } from '@mantine/hooks';
33
import { PiMagnifyingGlass } from 'react-icons/pi';
4+
import { Link as RemixLink } from "@remix-run/react";
45

56
import classes from './HeaderSearch.module.css';
67
import RegexZoneSvg from '../Logos/RegexZoneSvg';
@@ -16,18 +17,13 @@ export function HeaderSearch() {
1617
const [opened, { toggle }] = useDisclosure(false);
1718

1819
const items = links.map((link) => (
19-
<a
20+
<RemixLink
2021
key={link.label}
21-
href={link.link}
22+
to={link.link}
2223
className={classes.link}
23-
onClick={(event) => {
24-
if (!link.link.startsWith("https://")) {
25-
event.preventDefault()
26-
}
27-
}}
2824
>
2925
{link.label}
30-
</a>
26+
</RemixLink>
3127
));
3228

3329
return (

app/components/Library.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import * as fsPromises from "node:fs/promises";
2+
import * as path from "node:path";
3+
import * as yaml from "js-yaml";
4+
5+
const LIBRARY_DIR = path.join(process.cwd(), "library");
6+
7+
export type LibraryEntry = {
8+
title: string;
9+
handle: string;
10+
fullPath: string;
11+
};
12+
13+
const cache: Map<string, LibraryEntry> = new Map();
14+
const all: LibraryEntry[] = [];
15+
16+
async function initialize() {
17+
const fileNames = await fsPromises.readdir(LIBRARY_DIR);
18+
for await (const fileName of fileNames) {
19+
const fullPath = path.join(LIBRARY_DIR, fileName);
20+
console.log(`filename=${fullPath}`);
21+
22+
const raw = await fsPromises.readFile(fullPath, "utf-8");
23+
const parsed = yaml.load(raw, {
24+
fullPath,
25+
schema: yaml.JSON_SCHEMA,
26+
}) as LibraryEntry;
27+
parsed.fullPath = fullPath;
28+
29+
cache.set(parsed.handle, parsed);
30+
//LATER: validate w/JSON schema
31+
all.push(parsed);
32+
}
33+
}
34+
35+
function get(handle: string) {
36+
37+
const entry = cache.get(handle);
38+
39+
if (!entry) {
40+
throw new Error(`Unknown catalog entry ${handle}`);
41+
}
42+
43+
return entry;
44+
}
45+
46+
function getAll(): LibraryEntry[] {
47+
48+
return all;
49+
}
50+
51+
initialize();
52+
53+
export { get, getAll, initialize };

app/routes/_index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { HeaderSearch } from "~/components/HeaderSearch/HeaderSearch";
66
export const meta: MetaFunction = () => {
77
return [
88
{ title: "Regex Zone" },
9-
{ name: "description", content: "A library of useful regular expressions" },
9+
{ name: "description", content: "Useful regular expression resources" },
1010
];
1111
};
1212

app/routes/library.$entry._index.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { MetaFunction } from "@remix-run/node";
2+
import { Text } from '@mantine/core';
3+
4+
import { HeaderSearch } from "~/components/HeaderSearch/HeaderSearch";
5+
import { get, LibraryEntry } from "~/components/Library";
6+
import { useParams } from "@remix-run/react";
7+
8+
9+
export const meta: MetaFunction = () => {
10+
return [
11+
{ title: "Library - Regex Zone" },
12+
{ name: "description", content: "A library of useful regular expressions" },
13+
];
14+
};
15+
16+
export default function Index() {
17+
18+
const params = useParams()
19+
20+
const entry:LibraryEntry = get(params.entry || "");
21+
22+
return (
23+
<>
24+
<HeaderSearch />
25+
<Text>{JSON.stringify(entry)}</Text>
26+
</>
27+
);
28+
}

app/routes/library._index.tsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import type { MetaFunction } from "@remix-run/node";
2+
import { Table } from '@mantine/core';
3+
import { Link as RemixLink } from "@remix-run/react";
4+
5+
import { HeaderSearch } from "~/components/HeaderSearch/HeaderSearch";
6+
import { getAll, LibraryEntry } from "~/components/Library";
7+
8+
9+
export const meta: MetaFunction = () => {
10+
return [
11+
{ title: "Library - Regex Zone" },
12+
{ name: "description", content: "A library of useful regular expressions" },
13+
];
14+
};
15+
16+
function LibraryEntryRow( entry: LibraryEntry ) {
17+
return (
18+
<Table.Tr key={entry.handle}>
19+
<Table.Td>
20+
<RemixLink to={`${entry.handle}/`}>{entry.title}</RemixLink>
21+
</Table.Td>
22+
</Table.Tr>
23+
);
24+
}
25+
26+
export default function Index() {
27+
28+
const entries = getAll().map((entry) => LibraryEntryRow(entry));
29+
30+
return (
31+
<>
32+
<HeaderSearch />
33+
<Table>
34+
<Table.Thead>
35+
<Table.Tr>
36+
<Table.Th>Title</Table.Th>
37+
</Table.Tr>
38+
</Table.Thead>
39+
<Table.Tbody>
40+
{entries}
41+
</Table.Tbody>
42+
</Table>
43+
</>
44+
);
45+
}

library/color.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
featured: true
2+
handle: css-color
3+
title: CSS Colors
4+
tags:
5+
- color
6+
- css
7+
- html
8+
variations:
9+
- title: "Hex (standalone)"
10+
pattern: "^(#([a-fA-F0-9]{6}|[a-fA-F0-9]{3}))$"
11+
tests:
12+
- text: "#f00"
13+
- text: "#ff0000"
14+
- text: "#0f0"
15+
- text: "#00ff00"
16+
- text: "#00f"
17+
- text: "#0000ff"
18+
- text: "#000"
19+
- text: "#000000"
20+
- text: "#fff"
21+
- text: "#ffffff"
22+
- title: "Hex (inline)"
23+
pattern: "\\b(#([a-fA-F0-9]{6}|[a-fA-F0-9]{3}))\\b"

library/roman-numeral.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
featured: true
2+
handle: roman-numeral
3+
title: Roman Numerals
4+
variations:
5+
- title: "Roman Numerals (standalone)"
6+
pattern: "^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$"
7+
- title: "Roman Numerals (inline)"
8+
pattern: "\\bM{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})\\b"

0 commit comments

Comments
 (0)