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

docs: fix links #152

Merged
merged 1 commit into from
Feb 12, 2025
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
11 changes: 9 additions & 2 deletions docs/src/lib/stores/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { snakeCase } from 'change-case';
import { findMetadata } from '$lib/data';
import metadata from '$lib/data/metadata.json';
import { persistent } from '$stores/persistent';
Expand All @@ -24,8 +25,14 @@ class CurrentPlugin {

export const currentPlugin = new CurrentPlugin();

export const currentMetadata = derived(currentPlugin, derive, findMetadata(DEFAULT_PLUGIN));
export const currentMetadata = derived(currentPlugin, deriveMetadata, findMetadata(DEFAULT_PLUGIN));

function derive(current: TauriPlugin | null) {
function deriveMetadata(current: TauriPlugin | null) {
return findMetadata(current ?? DEFAULT_PLUGIN);
}

export function getCollectionName(plugin: Metadata, transform = snakeCase) {
return (plugin.name as TauriPlugin) === 'tauri-store'
? transform('store_collection')
: transform(plugin.title);
}
9 changes: 4 additions & 5 deletions docs/src/routes/guide/accessing-from-rust/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@
import { Ext } from '$components/link';
import { pascalCase } from 'change-case';
import { CodeBlock } from '$components/code';
import { currentMetadata } from '$stores/plugin';
import { Container } from '$components/container';
import { Breadcrumb } from '$components/breadcrumb';
import { currentMetadata, getCollectionName } from '$stores/plugin';
import { get, tryGet, watchStore } from '$content/guide/accessing-from-rust/snippets';

const url = $derived.by(() => {
const docs = $currentMetadata.docs;
const title = $currentMetadata.title;
const pascalTitle = pascalCase(title);
const collection = getCollectionName($currentMetadata, pascalCase);
return {
// Rust
ManagerExt: `${docs.rust}/trait.ManagerExt.html`,
Store: `${docs.rust}/struct.Store.html`,
try_get: `${docs.rust}/struct.${pascalTitle}.html#method.try_get`,
watch: `${docs.rust}/struct.${pascalTitle}.html#method.watch`,
try_get: `${docs.rust}/struct.${collection}.html#method.try_get`,
watch: `${docs.rust}/struct.${collection}.html#method.watch`,

// Tauri
AppHandle: 'https://docs.rs/tauri/latest/tauri/struct.AppHandle.html',
Expand Down
19 changes: 2 additions & 17 deletions docs/src/routes/guide/lifecycle-hooks/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
const docs = $currentMetadata.docs;
return {
// JavaScript
beforeBackendSync: `${docs.javascript}/interfaces/StoreHooks.html#beforebackendsync`,
beforeFrontendSync: `${docs.javascript}/interfaces/StoreHooks.html#beforefrontendsync`,
hooks: `${docs.javascript}/interfaces/StoreFrontendOptions.html#hooks`,
error: `${docs.javascript}/interfaces/StoreHooks.html#error`,
StoreHooks: `${docs.javascript}/types/StoreHooks.html`,

// Rust
on_load: `${docs.rust}/struct.Builder.html#method.on_load`,
Expand Down Expand Up @@ -51,16 +48,12 @@
<Container title="Lifecycle hooks" level={1}></Container>

<Container title="JavaScript">
<p>JavaScript hooks can be registered using the {@render ext('hooks')} option.</p>
<p>JavaScript hooks can be registered using the {@render ext('StoreHooks', 'hooks')} option.</p>

<CodeBlock lang="typescript" code={$jsHooks} />
</Container>

<Container title="beforeBackendSync" level={3}>
{#snippet titleSnippet({ title })}
<Ext href={url.beforeBackendSync}>{title}</Ext>
{/snippet}

<p>
Registers a hook to be called before a store sends its state to Rust. This can be used to modify
the state before it is sent to the backend.
Expand All @@ -79,10 +72,6 @@
</Container>

<Container title="beforeFrontendSync" level={3}>
{#snippet titleSnippet({ title })}
<Ext href={url.beforeFrontendSync}>{title}</Ext>
{/snippet}

<p>
Registers a hook to be called before a store attempts to update itself with data from Rust. This
can be used to modify the state before the changes are applied.
Expand All @@ -92,10 +81,6 @@
</Container>

<Container title="error" level={3}>
{#snippet titleSnippet({ title })}
<Ext href={url.error}>{title}</Ext>
{/snippet}

<p>Registers a hook to be called when an error is thrown by a store.</p>

<CodeBlock lang="typescript" code={onError} />
Expand Down
4 changes: 2 additions & 2 deletions docs/src/routes/guide/persisting-state/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
const docs = $currentMetadata.docs;
return {
// JavaScript
saveOnChange: `${docs.javascript}/interfaces/StoreBackendOptions.html#saveonchange`,
StoreBackendOptions: `${docs.javascript}/types/StoreBackendOptions.html`,

// Rust
autosave: `${docs.rust}/struct.Builder.html#method.autosave`,
Expand Down Expand Up @@ -54,7 +54,7 @@
<Container title="Save on change">
<p>
If there's a need to save a store whenever its state changes, you can enable the
{@render ext('saveOnChange')} option when defining the store.
{@render ext('StoreBackendOptions', 'saveOnChange')} option when defining the store.
</p>

<CodeBlock lang="typescript" code={$saveOnChange} />
Expand Down