Skip to content

Commit d97ffe1

Browse files
Pollepsjoepio
authored andcommitted
Next Template improvements #966
1 parent c4da291 commit d97ffe1

16 files changed

+49
-905
lines changed

browser/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ This changelog covers all five packages, as they are (for now) updated as a whol
5252

5353
### @tomic/create-template
5454

55-
- [#700](https://github.com/atomicdata-dev/atomic-server/issues/700) Update SvelteKit-site template to Svelte 5.
55+
- [#700](https://github.com/atomicdata-dev/atomic-server/issues/700) Update SvelteKit-site template to Svelte 5 and the new @tomic/svelte.
56+
- [#966](https://github.com/atomicdata-dev/atomic-server/issues/966) Add NextJS template.
57+
- [#993](https://github.com/atomicdata-dev/atomic-server/issues/993) Fix template not working when the drive subject has a path after the origin.
5658

5759
## [v0.40.0] - 2024-10-07
5860

browser/create-template/templates/nextjs-site/src/components/MarkdownContent.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import { remark } from 'remark';
77
import { TextBlock } from '@/ontologies/website';
88
import styles from '@/views/Block/TextBlock.module.css';
99

10+
/**
11+
* Component that renders markdown content.
12+
* It is hydrated on the client and will update whenever the markdown on the server changes.
13+
*/
1014
export const MarkdownContent = ({
1115
subject,
1216
initialContent,

browser/create-template/templates/nextjs-site/src/components/Navbar.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.nav {
22
gap: 1rem;
3-
padding: 2rem 1rem;
3+
padding-block: 2rem;
44
border-bottom: 1px solid var(--theme-color-bg-1);
55
}
66

browser/create-template/templates/nextjs-site/src/components/Searchbar.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ const Searchbar = () => {
3434
src={FaMagnifyingGlass}
3535
alt='search'
3636
/>
37-
38-
{styles.hallo}
3937
<input
4038
className={styles.input}
4139
type='search'

browser/create-template/templates/nextjs-site/src/views/Block/ImageGalleryBlock.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.wrapper {
1+
.imageGrid {
22
width: 100%;
33
display: grid;
44
grid-template-columns: repeat(

browser/create-template/templates/nextjs-site/src/views/Block/ImageGalleryBlock.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { Resource } from '@tomic/lib';
22
import { Image } from '@/components/Image';
33
import styles from './ImageGalleryBlock.module.css';
4+
import type { ImageGalleryBlock } from '@/ontologies/website';
45

5-
const ImageGalleryBlock = async ({ resource }: { resource: Resource }) => {
6+
const ImageGalleryBlock = async ({
7+
resource,
8+
}: {
9+
resource: Resource<ImageGalleryBlock>;
10+
}) => {
611
return (
712
<>
8-
{resource.props.name ? <h2>{resource.props.name}</h2> : null}
9-
10-
<div className={styles.wrapper}>
13+
{resource.props.name && <h2>{resource.props.name}</h2>}
14+
<div className={styles.imageGrid}>
1115
{resource.props.images?.map((image: string, index: number) => (
1216
<div key={index} className={styles.image}>
1317
<Image subject={image} alt='' />

browser/create-template/templates/nextjs-site/src/views/Block/TextBlock.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@
44
& p {
55
margin-top: 1em;
66
}
7+
8+
& :is(h1, h2, h3, h4, h5, h6) {
9+
margin-top: 1rem;
10+
}
711
}

browser/create-template/templates/nextjs-site/src/views/DefaultView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Resource } from '@tomic/react';
22

33
const DefaultView = async ({ resource }: { resource: Resource }) => {
44
console.error(
5-
`Error: Unable to find a valid page view for the specified class: "${resource.getClasses}". Please ensure that the class is correctly matched using matchClass. See documentation for details: https://docs.atomicdata.dev/js-lib/resource.html?highlight=matchClass#resourcematchclass`,
5+
`Error: Unable to find a valid page view for the specified class: "${resource.getClasses}". Make sure that the class is correctly matched using matchClass. See documentation for details: https://docs.atomicdata.dev/js-lib/resource.html#resourcematchclass`,
66
);
77

88
return <p>No supported view for {resource.title}.</p>;

browser/create-template/templates/nextjs-site/src/views/FullPage/BlogIndexPageFullPage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const BlogIndexPageFullPage = async ({
2121
const allItems = await getAllBlogposts();
2222
let results: string[] = [];
2323

24+
// We check if the searchParams have a search query. If so, we search for blogposts that match the query.
25+
// If there is no search query, we show all blogposts.
2426
if (searchParams?.search && typeof searchParams.search === 'string') {
2527
results = await store.search(searchParams.search, {
2628
filters: {
@@ -52,7 +54,7 @@ const BlogIndexPageFullPage = async ({
5254
<Searchbar />
5355
</Suspense>
5456
</HStack>
55-
{results.length !== 0 ? (
57+
{results.length > 0 ? (
5658
<ul>
5759
{results.map(post => (
5860
<li key={post}>

browser/create-template/templates/nextjs-site/src/views/FullPage/BlogpostFullPage.module.css

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
.blogWrapper {
22
padding: 1rem;
3+
}
4+
5+
.publishDate {
6+
color: var(--theme-color-text-light);
7+
margin-bottom: 2rem;
8+
}
9+
10+
.coverImageWrapper {
11+
height: 25rem;
312

413
& picture > img {
514
width: 100%;
@@ -9,11 +18,6 @@
918
}
1019
}
1120

12-
.blogWrapper > .publishDate {
13-
color: var(--theme-color-text-light);
14-
margin-bottom: 2rem;
15-
}
16-
1721
.content {
1822
max-width: 70ch;
1923
margin: auto;

browser/create-template/templates/nextjs-site/src/views/FullPage/BlogpostFullPage.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,22 @@ import html from 'remark-html';
88
import { remark } from 'remark';
99
import { MarkdownContent } from '@/components/MarkdownContent';
1010

11-
const BlogpostFullPage = ({ resource }: { resource: Resource<Blogpost> }) => {
12-
const formatter = new Intl.DateTimeFormat('default', {
13-
year: 'numeric',
14-
month: 'long',
15-
day: 'numeric',
16-
});
11+
const formatter = new Intl.DateTimeFormat('default', {
12+
year: 'numeric',
13+
month: 'long',
14+
day: 'numeric',
15+
});
1716

17+
const BlogpostFullPage = ({ resource }: { resource: Resource<Blogpost> }) => {
1818
const date = formatter.format(new Date(resource.props.publishedAt));
19-
2019
const matterResult = matter(resource.props.description);
2120
const processed = remark().use(html).processSync(matterResult.content);
2221
const initialContent = processed.toString();
2322

2423
return (
2524
<Container>
2625
<div className={styles.blogWrapper}>
27-
<div style={{ height: '25rem' }}>
26+
<div className={styles.coverImageWrapper}>
2827
<Image subject={resource.props.coverImage} alt='' />
2928
</div>
3029
<div className={styles.content}>

browser/create-template/templates/nextjs-site/src/views/FullPage/DefaultFullPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Resource } from '@tomic/lib';
33

44
const DefaultFullPage = async ({ resource }: { resource: Resource }) => {
55
console.error(
6-
`Error: Unable to find a valid page view for the specified class: "${resource.getClasses}". Please ensure that the class is correctly matched using matchClass. See documentation for details: https://docs.atomicdata.dev/js-lib/resource.html?highlight=matchClass#resourcematchclass`,
6+
`Error: Unable to find a valid page view for the specified class: "${resource.getClasses}". Make sure that the class is correctly matched using matchClass. See documentation for details: https://docs.atomicdata.dev/js-lib/resource.html?highlight=matchClass#resourcematchclass`,
77
);
88

99
return (

browser/create-template/templates/nextjs-site/src/views/FullPage/FullPageView.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const FullPageView = async ({
1414
}) => {
1515
const resource = await store.getResource(subject);
1616

17+
// Pick a component based on the resource's class.
1718
const Component = resource.matchClass(
1819
{
1920
[website.classes.page]: PageFullPage,
@@ -23,11 +24,7 @@ const FullPageView = async ({
2324
DefaultFullPage,
2425
);
2526

26-
if (Component === BlogIndexPageFullPage) {
27-
return <Component resource={resource} searchParams={searchParams} />;
28-
}
29-
30-
return <Component resource={resource} />;
27+
return <Component resource={resource} searchParams={searchParams} />;
3128
};
3229

3330
export default FullPageView;

browser/create-template/templates/nextjs-site/src/views/FullPage/PageFullPage.module.css

Lines changed: 0 additions & 10 deletions
This file was deleted.

browser/create-template/templates/nextjs-site/src/views/FullPage/PageFullPage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import type { Resource } from '@tomic/lib';
22
import BlockView from '../Block/BlockView';
33
import { type Page } from '@/ontologies/website';
4-
import styles from './PageFullPage.module.css';
54
import Container from '@/components/Layout/Container';
5+
import VStack from '@/components/Layout/VStack';
66

77
const PageFullPage = ({ resource }: { resource: Resource<Page> }) => {
88
const title = resource.title;
99

1010
return (
1111
<Container>
12-
<div className={styles.wrapper}>
12+
<VStack>
1313
<h1>{title?.toString()}</h1>
1414

1515
{resource.props.blocks?.map(block => (
1616
<BlockView key={block} subject={block} />
1717
))}
18-
</div>
18+
</VStack>
1919
</Container>
2020
);
2121
};

0 commit comments

Comments
 (0)