Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate <p> rendering and organize tests #195

Merged
merged 10 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ Below are VS Code extensions used in this project.

## Development

### Useful Commands

#### Convert `.ndjson` to `.json`

Required software: `jq`

```bash
jq --slurp '.' in.json > out.json
```

Retrieved from: <https://stackoverflow.com/questions/45456414/convert-json-lines-to-json-array-using-jq>

### Route Enforcement

To enforce categories and routes, we are using `src/params` to enforce only
Expand All @@ -169,12 +181,7 @@ of SvelteKit.
CI requires unit tests and perhaps integration tests if you could secure a
development key. This comes with managing the secret on GitHub, though.

We are either using Cloudflare Pages or Vercel to deploy the frontend. The
backend is deployed via the Sanity CLI deploy command. The frontend requires the
environment variables to be injected at build time in order to build and deploy
successfully. These can be accessed in either Cloudflare page's or Vercel's
appropriate deploy configuration settings. Make sure all of the .env.example
fields are used in the deployment environment.
The frontend is deployed to Cloudflare pages. The backend is deployed via the Sanity CLI deploy command. The frontend requires the environment variables to be injected at build time in order to build and deploy successfully. These can be accessed in either Cloudflare page's or Vercel's appropriate deploy configuration settings. Make sure all of the .env.example fields are used in the deployment environment.

## Useful Links

Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"*.{html,css,json,svelte}": ["yarn prettier --write"]
},
"dependencies": {
"@portabletext/svelte": "^2.1.11",
"@eirikk/portabletext-2-svelte-5": "^0.1.0-alpha.2",
"@portabletext/svelte": "^2",
"@sanity/client": "^6.22.5",
"@sanity/icons": "^3.4.0",
"@sanity/image-url": "^1.1.0",
Expand Down Expand Up @@ -74,5 +75,8 @@
"vite": "^5.4.11",
"vitest": "^2.1.5",
"wrangler": "^3.90.0"
},
"resolutions": {
"@portabletext/svelte": "npm:@eirikk/[email protected]"
}
}
3 changes: 2 additions & 1 deletion packages/frontend/src/components/Header.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script>
import { site } from '$lib/variables';
import Navbar from './general/Navbar.svelte';

import SiteTitle from './SiteTitle.svelte';
Expand All @@ -8,7 +9,7 @@
<a href="/" class="center">
<div class="w-100 flex flex-wrap items-center ma0 pa0">
<div class="mw3 mw4-ns">
<img src="/favicon.svg" alt="On Magnolia Square logo" class="mw-100" />
<img src="/favicon.svg" alt={`${site.name} logo`} class="mw-100" />
</div>
<div>
<SiteTitle />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
let link = parseEmbedLink(portableText.value.contentUrl);
</script>

<div class="mb4">
<div class="mv4">
{#if link.name == 'spotify'}
<SpotifyEmbed spotifyPath={link.path!} />
{/if}
Expand Down
36 changes: 19 additions & 17 deletions packages/frontend/src/components/portabletext/ArticleImage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,33 @@
let { portableText }: Props = $props();
</script>

<figure class="ma2 mb4 mw6 center">
<figure role="group" class="ma2 mb4 mw6 center">
<img
src={urlFor(portableText.value).fit('max').auto('format').url()}
alt={portableText.value.alt}
loading="lazy"
/>
{#if portableText.value.title}
<h4 class="ph1 fw5 i ma0 mb3 mt2">{portableText.value.title}</h4>
{/if}
{#if portableText.value.description || portableText.value.attrs.creditLine}
<figcaption class="fw5 f6 gray ph1">
<div class="flex flex-column">
{#if portableText.value.description}
<div>
{portableText.value.description}
<figcaption>
{#if portableText.value.title}
<h2 id="fig-title" class="ph1 fw5 i ma0 mb3 mt2 f4">{portableText.value.title}</h2>
{/if}
{#if portableText.value.description || portableText.value.attrs.creditLine}
<div class="fw5 f6 gray ph1">
<div class="flex flex-column">
{#if portableText.value.description}
<div>
{portableText.value.description}
</div>
{/if}
<div class="mt1">
<p class="pa0 ma0 i o-40">
Photo credit: {portableText.value.attrs.creditLine}
</p>
</div>
{/if}
<div class="mt1">
<p class="pa0 ma0 i o-40">
Photo credit: {portableText.value.attrs.creditLine}
</p>
</div>
</div>
</figcaption>
{/if}
{/if}
</figcaption>
</figure>

<style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@
{:else if style === 'blockquote'}
<blockquote>{@render children?.()}</blockquote>
{:else if style === 'normal'}
<!-- add class `db` to display as block, rather than inline <p> -->
<p class="lh-copy f5 f4-l tracked-02 fw4 pa0 mt0 mb4 tl hyphenate db w-100">
{@render children?.()}
</p>
{#if value.children.length === 1 && value.children[0].text === ''}
<br />
{:else}
<p class="lh-copy f5 f4-l tracked-02 fw3 pa0 pb0 mt0 mb2 tl hyphenate w-100 db">
{@render children?.()}
</p>
{/if}
{:else}
{@render children?.()}
{/if}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script lang="ts">
import type { BlockComponentProps } from '$lib/rendererTypes';
import type { Snippet } from 'svelte';

interface Props {
portableText: BlockComponentProps;
children?: import('svelte').Snippet;
children?: Snippet;
}

let { portableText, children }: Props = $props();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script lang="ts">
import type { MarkComponentProps } from '$lib/rendererTypes';
import type { Snippet } from 'svelte';

interface Props {
portableText: MarkComponentProps;
children?: import('svelte').Snippet;
children?: Snippet;
}

let { portableText, children }: Props = $props();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import type { Article } from '$lib/schema';
import type { PageServerLoad } from './$types';

export const load: PageServerLoad = (async (event: ServerLoadEvent) => {
let sanityQuery: string;

const { category, slug } = event.params;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@
import ArticleLink from '$components/portabletext/ArticleLink.svelte';
import NormalCentering from '$components/NormalCentering.svelte';
import { urlFor } from '$lib/sanity';
import {
PortableText,
ArticleSingleArticleBlock,
ArticleImage,
ArticleBodyMarks,
Tag
} from '$lib';
import { ArticleSingleArticleBlock, ArticleImage, ArticleBodyMarks, Tag } from '$lib';
import { fly } from 'svelte/transition';
import ArticleLeadIn from '$components/portabletext/ArticleLeadIn.svelte';
import { PortableText } from '@portabletext/svelte';

interface Props {
data: PageData;
Expand Down Expand Up @@ -111,7 +106,6 @@
}}
/>
</div>
<!-- <NormalCentering></NormalCentering> -->
</section>
</article>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect, vi } from 'vitest';
import { preflightOptions } from './hooks.server';
import { preflightOptions } from '../hooks.server';

describe('preflightOptions', () => {
it('should return 200 OK for OPTIONS requests', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import {
getConditions,
getIdx,
getOrder,
sanityFetch,
unequal
} from '$lib/sanity';
import type { Query } from '$lib/schema';
import { describe, it, expect, vi } from 'vitest';
import { describe, it, expect } from 'vitest';

describe('equal', () => {
it('returns correct GROQ query string for string comparison', () => {
Expand Down
Loading
Loading