-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(sdk): Create Astro Example for UVE (#29665)
# Proposed changes 1. Add new Astro project under `examples` folder 2. Install necessary dependencies to make it work as the other examples (Tailwind and Vercel plugin) 3. Add env file 4. Install `client` and `react` SDKs 5. Create React components to interop Astro with the React SDK 6. Clean the project by creating types and centralizing logic 7. Update readme file to add steps of how to set it up ## Screenshot https://github.com/user-attachments/assets/4d5f151e-169d-4bfa-b62d-b2447fe84f23 --------- Co-authored-by: Freddy Montes <[email protected]>
- Loading branch information
Showing
45 changed files
with
9,960 additions
and
24 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
31 changes: 20 additions & 11 deletions
31
core-web/libs/sdk/client/src/lib/utils/page/common-utils.ts
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
PUBLIC_DOTCMS_AUTH_TOKEN=YOUR_API_TOKEN | ||
PUBLIC_DOTCMS_HOST=http://localhost:8080 | ||
PUBLIC_DOTCMS_SITE_ID=your-dotcms-site-id | ||
PUBLIC_EXPERIMENTS_API_KEY=analytic-api-key-from-dotcms-portlet | ||
PUBLIC_EXPERIMENTS_DEBUG=true | ||
# If your local dotcms instance is running in https, this setting allows Node.js to connect to servers with invalid SSL certificates. | ||
# For testing purposes only. | ||
NODE_TLS_REJECT_UNAUTHORIZED=0 | ||
|
||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# build output | ||
dist/ | ||
|
||
# generated types | ||
.astro/ | ||
|
||
# dependencies | ||
node_modules/ | ||
|
||
# logs | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
|
||
# environment variables | ||
.env | ||
.env.production | ||
.env.local | ||
|
||
# macOS-specific files | ||
.DS_Store | ||
|
||
# jetbrains setting folder | ||
.idea/ |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** @type {import("prettier").Config} */ | ||
export default { | ||
plugins: ["prettier-plugin-astro"], | ||
overrides: [ | ||
{ | ||
files: "*.astro", | ||
options: { | ||
parser: "astro", | ||
}, | ||
}, | ||
], | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# dotCMS Astro Example | ||
|
||
DotCMS provides a Astro example that shows how to build dotCMS pages heedlessly with Astro JavaScript framework. | ||
|
||
## What do you need? | ||
|
||
1. A dotCMS instance or you can use https://demo.dotcms.com | ||
2. A valid AUTH token for the target instance (see: https://auth.dotcms.com/docs/latest/rest-api-authentication#creating-an-api-token-in-the-ui) | ||
3. A valid Site Identifier where your page is located (see: https://www.dotcms.com/docs/latest/multi-site-management#multi-site-management) | ||
4. Node js 18+ and npm installed | ||
5. Terminal | ||
6. And a code editor. | ||
|
||
### Create the new Astro application | ||
|
||
Open your terminal and let’s create the Astro app by running the following: | ||
|
||
```bash | ||
npm create astro@latest -- --template dotcms/core/examples/astro | ||
``` | ||
|
||
Follow the Astro setup steps after it pulls the example. | ||
|
||
## Add the dotCMS configuration | ||
|
||
Now we need to tell the Astro app what dotCMS instance is going to use to get the data to build its pages. | ||
|
||
1. Open the folder where you created the project in your code editor | ||
2. In the root, find the file `.env.local.example` and rename to `.env.local` | ||
3. Open the .env.local file and update the environment variable: | ||
|
||
- `PUBLIC_DOTCMS_AUTH_TOKEN` this is the auth token for dotCMS, you can use the dotCMS UI to create one. | ||
- `PUBLIC_DOTCMS_HOST` this is the instance of dotCMS where your pages and content lives (license needed) if you don’t have one, you can use [https://demo.dotcms.com](https://demo.dotcms.com) (be careful it restarts every 24h). | ||
- `PUBLIC_DOTCMS_SITE_ID` this is the identifier of the Site you are going to use for your website you can find it by going to Settings > Sites. Once there follow the next steps: | ||
|
||
1. Select the desired Site (A modal should be opened) | ||
2. Go to the History Tab | ||
3. Copy the `Identifier` that appears in the top of the tab | ||
|
||
## Run the app | ||
|
||
Once all the configuration is in place, it is time to run the web app. | ||
|
||
1. Go back to your terminal and from the folder you created the project | ||
2. Run `npm run dev` | ||
3. Open http://localhost:4321 in your browser (Verify the port Astro is using, 4321 is the default but it can change) | ||
|
||
🎉 And that’s it. | ||
|
||
Consider that if you go to `localhost:4321/about`, the page `/about` needs to exist in your dotCMS instance. |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { defineConfig } from "astro/config"; | ||
import react from "@astrojs/react"; | ||
import tailwind from "@astrojs/tailwind"; | ||
|
||
import vercel from "@astrojs/vercel/serverless"; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
integrations: [react(), tailwind()], | ||
output: "server", | ||
adapter: vercel(), | ||
}); |
Oops, something went wrong.