-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* style: update eslint config * style: run prettier * style: run prettier * style: run prettier --------- Co-authored-by: lihbr <lihbr@users.noreply.github.com>
- Loading branch information
Showing
297 changed files
with
5,613 additions
and
5,654 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
import * as prismic from "@prismicio/client"; | ||
import fetch from "node-fetch"; | ||
import QuickLRU from "quick-lru"; | ||
import * as prismic from "@prismicio/client" | ||
import fetch from "node-fetch" | ||
import QuickLRU from "quick-lru" | ||
|
||
const cache = new QuickLRU({ | ||
maxSize: 1000, // 1000 entries | ||
}); | ||
}) | ||
|
||
const client = prismic.createClient("qwerty", { | ||
fetch: async (url, options) => { | ||
// The cache key contains the requested URL and headers | ||
const key = JSON.stringify({ url, options }); | ||
const key = JSON.stringify({ url, options }) | ||
|
||
if (cache.has(key)) { | ||
// If the cache contains a value for the key, return it | ||
return cache.get(key).clone(); | ||
return cache.get(key).clone() | ||
} else { | ||
// Otherwise, make the network request | ||
const res = await fetch(url, options); | ||
const res = await fetch(url, options) | ||
|
||
if (res.ok) { | ||
// If the request was successful, save it to the cache | ||
cache.set(key, res.clone()); | ||
cache.set(key, res.clone()) | ||
} | ||
|
||
return res; | ||
return res | ||
} | ||
}, | ||
}); | ||
}) | ||
|
||
const homepage = await client.getByUID("page", "home"); | ||
console.info("First uncached result: ", homepage); | ||
const homepage = await client.getByUID("page", "home") | ||
console.info("First uncached result: ", homepage) | ||
// => The `page` document with a UID of `home` | ||
|
||
const homepageFetchedAgain = await client.getByUID("page", "home"); | ||
console.info("Second cached result: ", homepageFetchedAgain); | ||
const homepageFetchedAgain = await client.getByUID("page", "home") | ||
console.info("Second cached result: ", homepageFetchedAgain) | ||
// => This call will use the cache rather than make another network request. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
import * as prismic from "@prismicio/client"; | ||
import fetch from "node-fetch"; | ||
import * as prismic from "@prismicio/client" | ||
import fetch from "node-fetch" | ||
|
||
const client = prismic.createClient("qwerty", { | ||
fetch, | ||
}); | ||
}) | ||
|
||
// By default, the client will fetch the latest published content from the repository. | ||
// This means content is fetched from the "master ref". | ||
const homepage = await client.getByUID("page", "home"); | ||
console.info(homepage); | ||
const homepage = await client.getByUID("page", "home") | ||
console.info(homepage) | ||
|
||
// We can get a list of all refs in a repository. | ||
const refs = await client.getRefs(); | ||
console.info(refs); | ||
const refs = await client.getRefs() | ||
console.info(refs) | ||
|
||
// Or we can get a specific ref by its label. | ||
// If we have an ID instead, `client.getRefByID` can be used. | ||
const ref = await client.getRefByLabel("My Specific Ref"); | ||
const ref = await client.getRefByLabel("My Specific Ref") | ||
|
||
// If we want to query content from a specific ref, we can tell the client to | ||
// make all future queries use that ref. | ||
client.queryContentFromRef(ref.ref); | ||
client.queryContentFromRef(ref.ref) | ||
|
||
// Now queries will fetch content from the "My Specific Ref" ref. | ||
const aboutPage = await client.getByUID("page", "about"); | ||
console.info(aboutPage); | ||
const aboutPage = await client.getByUID("page", "about") | ||
console.info(aboutPage) | ||
|
||
// We can also override the ref on a per-query basis. | ||
const otherRef = await client.getRefByLabel("My Other Ref"); | ||
const otherRef = await client.getRefByLabel("My Other Ref") | ||
const contactPage = await client.getByUID("page", "contact", { | ||
ref: otherRef.ref, | ||
}); | ||
console.info(contactPage); | ||
}) | ||
console.info(contactPage) | ||
|
||
// We can change back to fetching the latest content with the following function. | ||
client.queryLatestContent(); | ||
client.queryLatestContent() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
import * as prismic from "@prismicio/client"; | ||
import fetch from "node-fetch"; | ||
import * as prismic from "@prismicio/client" | ||
import fetch from "node-fetch" | ||
|
||
const client = prismic.createClient("qwerty", { | ||
fetch, | ||
}); | ||
}) | ||
|
||
// By default, the client will fetch the latest published content from the repository. | ||
// This means content is fetched from the "master ref". | ||
const homepage = await client.getByUID("page", "home"); | ||
console.info(homepage); | ||
const homepage = await client.getByUID("page", "home") | ||
console.info(homepage) | ||
|
||
// We can get a list of all releases in a repository. | ||
const releases = await client.getReleases(); | ||
console.info(releases); | ||
const releases = await client.getReleases() | ||
console.info(releases) | ||
|
||
// Or we can get a specific release by its label. | ||
// If we have an ID instead, `client.getReleaseByID` can be used. | ||
const release = await client.getReleaseByLabel("My Specific Release"); | ||
console.info(release); | ||
const release = await client.getReleaseByLabel("My Specific Release") | ||
console.info(release) | ||
|
||
// We can tell the client to make all queries point to a released called "My Release". | ||
// We could also use `client.queryContentFromReleaseByID` if we have an ID instead. | ||
client.queryContentFromReleaseByLabel("My Release"); | ||
client.queryContentFromReleaseByLabel("My Release") | ||
|
||
// Now queries will fetch content from "My Release". | ||
const aboutPage = await client.getByUID("page", "about"); | ||
console.info(aboutPage); | ||
const aboutPage = await client.getByUID("page", "about") | ||
console.info(aboutPage) | ||
|
||
// We can also override the release on a per-query basis. | ||
const otherRelease = await client.getReleaseByLabel("My Other Release"); | ||
const otherRelease = await client.getReleaseByLabel("My Other Release") | ||
const contactPage = await client.getByUID("page", "contact", { | ||
ref: otherRelease.ref, | ||
}); | ||
console.info(contactPage); | ||
}) | ||
console.info(contactPage) | ||
|
||
// We can change back to fetching the latest content with the following function. | ||
client.queryLatestContent(); | ||
client.queryLatestContent() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import * as prismic from "@prismicio/client"; | ||
import fetch from "node-fetch"; | ||
import * as prismic from "@prismicio/client" | ||
import fetch from "node-fetch" | ||
|
||
const client = prismic.createClient("qwerty", { | ||
// Here, we provide a way for the client to make network requests. | ||
// `node-fetch` is a Node.js fetch-compatible package. | ||
fetch, | ||
}); | ||
}) | ||
|
||
const homepage = await client.getByUID("page", "home"); | ||
console.info(homepage); | ||
const homepage = await client.getByUID("page", "home") | ||
console.info(homepage) | ||
// => The `page` document with a UID of `home` |
Oops, something went wrong.