Skip to content

Commit 2a2a9cf

Browse files
broken links and auto open faqs when linked
1 parent ffc73bb commit 2a2a9cf

8 files changed

Lines changed: 121 additions & 18 deletions

File tree

docs/capabilities/devvit-web/devvit_web_overview.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ As with most experimental features, there are some caveats.
3535
| Limitation | What it means |
3636
| ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
3737
| Serverless endpoints | The node server will run just long enough to execute your endpoint function and return a response, which means you can't use packages that require long-running connections like streaming. |
38-
| Package limitations | Developers cannot use `fs` or external native packages. For now, we recommend using external services over the native dependencies, such as [StreamPot](https://streampot.io/) (instead of ffmpeg) and [OpenAI](https://platform.openai.com/docs/guides/embeddings) (instead of @xenova/transformers) . |
38+
| Package limitations | Developers cannot use `fs` or external native packages. For now, we recommend using external services over native dependencies. |
3939
| Single request and single response handling only | Streaming or chunked responses and websockets are not supported. Long-polling is supported if it's under the max request time. |
4040
| No external requests from your client | You can't have any external requests other than the app's webview domain. All backend responses are locked down to the webview domain via CSP. (Your backend can make external fetch requests though.) |
4141
| localStorage clears on app updates | The iframe URL changes with each app version, so `localStorage` data is lost when you publish an update. Use [Redis](../server/redis.mdx) for data that needs to persist across app versions. |

docs/capabilities/server/redis.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ Redis transactions allow a group of commands to be executed in a single isolated
615615
- Increment the count for selected option.
616616
- Add the user to voted user list.
617617

618-
The `watch` command provides an entrypoint for transactions. It returns a [TxClientLike](https://developers.reddit.com/docs/api/public-api/#-txclientlike) which can be used to call `multi`, `exec`, `discard`, `unwatch`, and all other Redis commands to be executed within a transaction.
618+
The `watch` command provides an entrypoint for transactions. It returns a [TxClientLike](https://developers.reddit.com/docs/api/public-api/type-aliases/TxClientLike) which can be used to call `multi`, `exec`, `discard`, `unwatch`, and all other Redis commands to be executed within a transaction.
619619

620620
You can sequence all of the above steps in a single transaction using `multi` and `exec` to ensure that either all of the steps happen together or none at all.
621621

@@ -626,7 +626,7 @@ If an error occurs inside a transaction before `exec` is called, Redis discards
626626
| [multi](https://redis.io/commands/multi/) | Marks the start of a transaction block. | Max concurrent transactions per installation: 20 (default) |
627627
| [exec](https://redis.io/commands/exec/) | Executes all previously queued commands in a transaction and restores the connection state to normal. | Transaction execution timeout: 5 seconds |
628628
| [discard](https://redis.io/commands/discard/) | Flushes all previously queued commands in a transaction and restores the connection state to normal. | None |
629-
| [watch](https://redis.io/commands/watch/) | Marks the given keys to be watched for conditional execution of a transaction. `watch` returns a [TxClientLike](https://developers.reddit.com/docs/api/public-api/#-txclientlike) which should be used to call Redis commands in a transaction. | None |
629+
| [watch](https://redis.io/commands/watch/) | Marks the given keys to be watched for conditional execution of a transaction. `watch` returns a [TxClientLike](https://developers.reddit.com/docs/api/public-api/type-aliases/TxClientLike) which should be used to call Redis commands in a transaction. | None |
630630
| [unwatch](https://redis.io/commands/unwatch/) | Flushes all the previously watched keys for a transaction. | None |
631631

632632
<details>

docs/devvit_rules.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
Welcome to Reddit’s Developer Platform (or “**Devvit**”)! Before you build, please read these Devvit Rules along with Reddit’s [Developer Terms](https://www.redditinc.com/policies/developer-terms). We want you and your Devvit app(s) to succeed, and our policies and developer documentation are designed to enable you to provide a fun, safe, and trusted experience for all redditors. We expect you to be honest about your app(s), and to respect the privacy, safety, and other rights of redditors.
66

7-
You must comply with: these Devvit Rules and Reddit’s [Developer Terms](https://www.redditinc.com/policies/developer-terms), [Developer Data Protection Addendum](https://www.redditinc.com/policies/developer-dpa), and [Data API Terms](https://www.redditinc.com/policies/data-api-terms); our [User Agreement](https://www.redditinc.com/policies/), [Econ Terms](https://www.redditinc.com/policies/econ-terms), [Previews Terms](https://www.redditinc.com/policies/previews-terms), [Privacy Policy](https://www.reddit.com/policies/privacy-policy), [Public Content Policy](https://support.reddithelp.com/hc/en-us/articles/26410290525844-Public-Content-Policy), [Reddit Rules](https://www.redditinc.com/policies/reddit-rules) and [Advertising Policy](https://redditinc.force.com/helpcenter/s/article/Reddit-Advertising-Policy-Restricted-Advertisements); and all other policies and developer documentation governing the use of our developer services (collectively, “**Reddit Terms & Policies**”). We may update Reddit Terms & Policies from time to time, so please check in and review them regularly.
7+
You must comply with: these Devvit Rules and Reddit’s [Developer Terms](https://www.redditinc.com/policies/developer-terms), [Developer Data Protection Addendum](https://www.redditinc.com/policies/developer-dpa), and [Data API Terms](https://www.redditinc.com/policies/data-api-terms); our [User Agreement](https://www.redditinc.com/policies/), [Econ Terms](https://www.redditinc.com/policies/econ-terms), [Previews Terms](https://www.redditinc.com/policies/previews-terms), [Privacy Policy](https://www.reddit.com/policies/privacy-policy), [Public Content Policy](https://support.reddithelp.com/hc/en-us/articles/26410290525844-Public-Content-Policy), [Reddit Rules](https://www.redditinc.com/policies/reddit-rules) and [Advertising Policy](https://business.reddithelp.com/s/article/Reddit-Advertising-Policy-Overview); and all other policies and developer documentation governing the use of our developer services (collectively, “**Reddit Terms & Policies**”). We may update Reddit Terms & Policies from time to time, so please check in and review them regularly.
88

99
## Reddit app review
1010

1111
Your app is subject to our app review and approval. Reddit may reject or remove any app that violates these Devvit Rules or any other Reddit Terms & Policies at our discretion. We may also suspend or ban accounts tied to developers who violate these Devvit Rules or any other Reddit Terms & Policies.
1212

13-
These Devvit Rules are intended to clarify how we review Devvit apps and streamline the process for you and Reddit. Our goal is to keep redditors safe and enable developers to build fun and useful apps for redditors. This means our Devvit Rules may evolve over time, which you should keep in mind when building or updating your app. Please [reach out](https://developers.reddit.com/docs/help) if you have any questions on these Devvit Rules. Any exceptions to these Devvit Rules or any other Reddit Terms & Policies must be approved in writing by Reddit.
13+
These Devvit Rules are intended to clarify how we review Devvit apps and streamline the process for you and Reddit. Our goal is to keep redditors safe and enable developers to build fun and useful apps for redditors. This means our Devvit Rules may evolve over time, which you should keep in mind when building or updating your app. Please [reach out](https://developers.reddit.com/docs/guides/faq#help-and-next-steps:~:text=For%20help%20from%20the%20Devvit%20team%20and%20community%3A) if you have any questions on these Devvit Rules. Any exceptions to these Devvit Rules or any other Reddit Terms & Policies must be approved in writing by Reddit.
1414

1515
You can use Devvit and test your app without needing to submit it to Reddit’s App Review. However, to make your app visible in the [Reddit App Directory](https://developers.reddit.com/apps) and publicly available for other mods and admins to install, you’ll need prior app approval. Additionally, if you want to unlock premium features for your app (for example, [payments](./earn-money/payments/payments_overview.md), [fetching](./capabilities/server/http-fetch.mdx), or [using LLMs](#generative-aillm-rules)), you’ll also need prior app approval.
1616

@@ -43,7 +43,7 @@ You are required to resubmit your app for Reddit app review every time you publi
4343

4444
We may require you to provide additional information to us in order to complete our app review. We also may periodically or randomly re-review your app and require you to make changes or otherwise face a suspension or ban of your app if we find it to no longer be compliant with these Devvit Rules and Reddit Terms & Policies.
4545

46-
If you have questions about Reddit’s app review and approval process or these Devvit Rules, please reach out for [help](https://developers.reddit.com/docs/help).
46+
If you have questions about Reddit’s app review and approval process or these Devvit Rules, please reach out for [help](https://developers.reddit.com/docs/guides/faq#help-and-next-steps:~:text=For%20help%20from%20the%20Devvit%20team%20and%20community%3A).
4747

4848
## General rules
4949

@@ -98,7 +98,7 @@ You and your app(s) must not:
9898

9999
### Don’t build restricted apps
100100

101-
You should not create an app or functionality that promotes or facilitates transactions in a prohibited or regulated industry such as (but not limited to) gambling, healthcare, financial and cryptocurrency products and services, political, alcohol, recreational drugs, or any other restricted category listed in the [Reddit Advertising Policy](https://redditinc.force.com/helpcenter/s/article/Reddit-Advertising-Policy-Restricted-Advertisements).
101+
You should not create an app or functionality that promotes or facilitates transactions in a prohibited or regulated industry such as (but not limited to) gambling, healthcare, financial and cryptocurrency products and services, political, alcohol, recreational drugs, or any other restricted category listed in the [Reddit Advertising Policy](https://business.reddithelp.com/s/article/Reddit-Advertising-Policy-Overview).
102102

103103
### No linking out to external apps
104104

@@ -160,13 +160,13 @@ Any content used or created by your Devvit app must comply with Reddit Terms & P
160160

161161
- **Using Existing User Content** – your app may copy and display existing Reddit user content and modify it for display, but only in compliance with Reddit’s [Developer Terms](https://www.redditinc.com/policies/developer-terms). User content on Reddit is owned by redditors and not by Reddit, so you must also comply with all requirements or restrictions imposed by the owners of user content. Ask redditors for their permission if you want to use existing user content in ways they might not expect (e.g., by building an in-app pop-up asking for redditor approval).
162162

163-
- **Generating New User Content** – your app may allow new user content to be created by redditors, but all user content must comply with Reddit’s [User Agreement](https://www.redditinc.com/policies/developer-terms), [Reddit Rules](https://www.redditinc.com/policies/reddit-rules), and [Advertising Policy](https://redditinc.force.com/helpcenter/s/article/Reddit-Advertising-Policy-Restricted-Advertisements).
163+
- **Generating New User Content** – your app may allow new user content to be created by redditors, but all user content must comply with Reddit’s [User Agreement](https://www.redditinc.com/policies/developer-terms), [Reddit Rules](https://www.redditinc.com/policies/reddit-rules), and [Advertising Policy](https://business.reddithelp.com/s/article/Reddit-Advertising-Policy-Overview).
164164

165165
- _Post or Comment Attribution Rules_ – if your app supports the creation of new posts or comments on Reddit by redditors, then you should create a new post or comment with the content author clearly identified as the author of the submitted content. Until your app is approved by Reddit, new content from your app will be posted from your Devvit app account. If your app is approved, then submitPost will post on behalf of the content author.
166166

167167
- _In-App Content Rules_ – if your app allows users to create new forms of user content within your app (for example, a form submission that modifies the content of your app), your app should limit the available forms of expression to prevent potential abuse. Appropriate examples of limited expression include emojis, symbols (e.g., stock tickers), and predefined, safe dictionaries. If you want to minimize the risk of abuse, avoid allowing users to create new in-app content through free-form text inputs in your app.
168168

169-
- **Displaying Devvit App Content** – your app may include information, materials, and other content that you provide and make available through your app. Your app content must also comply with these Devvit Rules, Reddit’s [User Agreement](https://www.redditinc.com/policies/developer-terms), [Reddit Rules](https://www.redditinc.com/policies/reddit-rules), and [Advertising Policy](https://redditinc.force.com/helpcenter/s/article/Reddit-Advertising-Policy-Restricted-Advertisements). You may not use external logos or trademarks in your app without express written permission.
169+
- **Displaying Devvit App Content** – your app may include information, materials, and other content that you provide and make available through your app. Your app content must also comply with these Devvit Rules, Reddit’s [User Agreement](https://www.redditinc.com/policies/developer-terms), [Reddit Rules](https://www.redditinc.com/policies/reddit-rules), and [Advertising Policy](https://business.reddithelp.com/s/article/Reddit-Advertising-Policy-Overview). You may not use external logos or trademarks in your app without express written permission.
170170

171171
If any content created or otherwise displayed through your app violates these Devvit Rules or other Reddit Terms & Policies, then Reddit may remove the content and/or request you remove the content. Failure to do so can result in your app being removed from Devvit.
172172

docusaurus.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const config: Config = {
6060
src: `${baseUrl}events.js`,
6161
},
6262
],
63+
clientModules: ["./src/client/openDetailsForHash.ts"],
6364

6465
// GitHub pages deployment config.
6566
// If you aren't using GitHub pages, you don't need these.

src/client/openDetailsForHash.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
type HashLocation = {
2+
hash: string;
3+
};
4+
5+
type RouteUpdateArgs = {
6+
location: HashLocation;
7+
};
8+
9+
const headingSelector = "h1, h2, h3, h4, h5, h6";
10+
11+
function getHashId(location: HashLocation): string | null {
12+
if (!location.hash) {
13+
return null;
14+
}
15+
16+
const hashWithoutPrefix = location.hash.slice(1);
17+
const hashBeforeTextFragment = hashWithoutPrefix.split(":~:")[0];
18+
19+
if (!hashBeforeTextFragment) {
20+
return null;
21+
}
22+
23+
try {
24+
return decodeURIComponent(hashBeforeTextFragment);
25+
} catch {
26+
return hashBeforeTextFragment;
27+
}
28+
}
29+
30+
function getTargetElement(id: string): HTMLElement | null {
31+
return (
32+
document.getElementById(id) ??
33+
(document.getElementsByName(id)[0] as HTMLElement | undefined) ??
34+
null
35+
);
36+
}
37+
38+
function openAncestorDetails(element: HTMLElement): HTMLDetailsElement | null {
39+
const details = element.closest("details");
40+
41+
if (details instanceof HTMLDetailsElement) {
42+
details.open = true;
43+
return details;
44+
}
45+
46+
return null;
47+
}
48+
49+
function openFollowingDetails(element: HTMLElement): HTMLDetailsElement | null {
50+
let sibling = element.nextElementSibling;
51+
52+
while (sibling) {
53+
if (sibling instanceof HTMLDetailsElement) {
54+
sibling.open = true;
55+
return sibling;
56+
}
57+
58+
if (sibling.matches(headingSelector)) {
59+
return null;
60+
}
61+
62+
sibling = sibling.nextElementSibling;
63+
}
64+
65+
return null;
66+
}
67+
68+
function openDetailsForCurrentHash(location: HashLocation = window.location): void {
69+
const id = getHashId(location);
70+
71+
if (!id) {
72+
return;
73+
}
74+
75+
const target = getTargetElement(id);
76+
77+
if (!target) {
78+
return;
79+
}
80+
81+
const openedDetails =
82+
openAncestorDetails(target) ?? openFollowingDetails(target);
83+
84+
if (openedDetails) {
85+
requestAnimationFrame(() => {
86+
target.scrollIntoView({ block: "start" });
87+
});
88+
}
89+
}
90+
91+
function scheduleOpenDetails(location: HashLocation = window.location): void {
92+
openDetailsForCurrentHash(location);
93+
window.setTimeout(() => openDetailsForCurrentHash(location), 100);
94+
}
95+
96+
if (typeof window !== "undefined") {
97+
window.addEventListener("hashchange", () => scheduleOpenDetails());
98+
}
99+
100+
export function onRouteDidUpdate({ location }: RouteUpdateArgs): void {
101+
scheduleOpenDetails(location);
102+
}

0 commit comments

Comments
 (0)