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

chore(sdk): Create Astro Example for UVE #29665

Merged
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
60e9361
init astro project
zJaaal Aug 20, 2024
5b61d24
Astro is running React Library
zJaaal Aug 20, 2024
572297e
add react components
zJaaal Aug 20, 2024
72324c4
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Aug 20, 2024
4bc5da1
Merge branch '29393-sdk-create-dotcms-example-for-javascript-framewor…
zJaaal Aug 20, 2024
fc86a6f
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Aug 21, 2024
222748c
astro now works inside the uve
zJaaal Aug 21, 2024
58aa434
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Aug 21, 2024
75715d7
Update myPage.tsx
zJaaal Aug 21, 2024
6e671a0
Merge branch '29393-sdk-create-dotcms-example-for-javascript-framewor…
zJaaal Aug 21, 2024
45efaaa
cleaning
zJaaal Aug 21, 2024
92eff87
cleaning
zJaaal Aug 21, 2024
0496fba
Update entry.tsx
zJaaal Aug 21, 2024
6501251
cleaning
zJaaal Aug 21, 2024
31dadbf
update to alpha 32
zJaaal Aug 22, 2024
2bb63c9
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Aug 22, 2024
d8a331a
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Aug 23, 2024
7e55500
fixing types
zJaaal Aug 23, 2024
ef02fa7
cleaning
zJaaal Aug 23, 2024
a5d1213
add types for layout
zJaaal Aug 23, 2024
d09eb32
fix types for components
zJaaal Aug 23, 2024
db70df2
Update usePageAsset.ts
zJaaal Aug 23, 2024
8c10365
formatting
zJaaal Aug 23, 2024
f328542
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Aug 23, 2024
48bc264
preserve query params
zJaaal Aug 23, 2024
d61cdf7
Merge branch '29393-sdk-create-dotcms-example-for-javascript-framewor…
zJaaal Aug 23, 2024
bf908d0
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Aug 24, 2024
12559c9
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Aug 26, 2024
549a17b
clean env local example
zJaaal Aug 26, 2024
7aa488b
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Aug 26, 2024
2c58718
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Aug 26, 2024
52a6cbf
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Aug 27, 2024
1127731
Update calendarEvent.tsx
zJaaal Aug 27, 2024
0dde0cb
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Aug 28, 2024
a5a63aa
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Aug 29, 2024
02f1bb9
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Aug 29, 2024
5d78cc9
update libs
zJaaal Sep 2, 2024
2ad96f5
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Sep 2, 2024
074cf6c
Update Readme
zJaaal Sep 2, 2024
25f05e1
Update README.md
zJaaal Sep 2, 2024
627e49f
Update README.md
zJaaal Sep 2, 2024
7de493c
move logic to sdk and clean example
zJaaal Sep 2, 2024
61d1409
Update header.tsx
zJaaal Sep 2, 2024
68bf766
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Sep 2, 2024
69b4b96
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Sep 2, 2024
973dbf3
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Sep 3, 2024
9e4c732
Update examples/astro/README.md
zJaaal Sep 3, 2024
4671d8e
Update examples/astro/README.md
zJaaal Sep 3, 2024
948a790
simplify example and fix error styles
zJaaal Sep 3, 2024
ac661ca
use aliases for imports
zJaaal Sep 3, 2024
01f3938
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Sep 3, 2024
8102ed8
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Sep 3, 2024
497b013
add dotcms favicon
zJaaal Sep 4, 2024
d89536c
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Sep 4, 2024
634740a
Update Layout.astro
zJaaal Sep 4, 2024
a13ba98
fix astro example for calendar event
zJaaal Sep 4, 2024
741798f
Merge branch 'master' into 29393-sdk-create-dotcms-example-for-javasc…
zJaaal Sep 4, 2024
c0ba941
change to current version
zJaaal Sep 4, 2024
12433d0
Update calendarEvent.tsx
zJaaal Sep 4, 2024
176c6a9
correct version
zJaaal Sep 4, 2024
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
4 changes: 2 additions & 2 deletions core-web/libs/sdk/angular/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "@dotcms/angular",
"version": "0.0.1-alpha.35",
"version": "0.0.1-alpha.37",
"peerDependencies": {
"@angular/common": "^17.1.0",
"@angular/core": "^17.1.0",
"@angular/router": "^17.1.0",
"@dotcms/client": "0.0.1-alpha.35",
"@dotcms/client": "0.0.1-alpha.37",
"@tinymce/tinymce-angular": "^8.0.0",
"rxjs": "^7.8.0"
},
Expand Down
2 changes: 1 addition & 1 deletion core-web/libs/sdk/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dotcms/client",
"version": "0.0.1-alpha.35",
"version": "0.0.1-alpha.37",
"description": "Official JavaScript library for interacting with DotCMS REST APIs.",
"repository": {
"type": "git",
Expand Down
31 changes: 20 additions & 11 deletions core-web/libs/sdk/client/src/lib/utils/page/common-utils.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
interface PageRequestParamsProps {
path: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
params: { [key: string]: any } | undefined; // QueryParams are typed as `any` in frameworks
params: { [key: string]: any } | undefined | URLSearchParams; // QueryParams are typed as `any` in frameworks
zJaaal marked this conversation as resolved.
Show resolved Hide resolved
}

export const getPageRequestParams = ({ path = '', params = {} }: PageRequestParamsProps) => {
export const getPageRequestParams = ({
zJaaal marked this conversation as resolved.
Show resolved Hide resolved
path = '',
params = {}
}: PageRequestParamsProps): {
path: string;
[key: string]: string | number;
} => {
const copiedParams: PageRequestParamsProps['params'] =
params instanceof URLSearchParams ? Object.fromEntries(params.entries()) : { ...params };

const finalParams: Record<string, unknown> = {};
const dotMarketingPersonaId = params['com.dotmarketing.persona.id'] || '';
const dotMarketingPersonaId = copiedParams['com.dotmarketing.persona.id'] || '';

if (params['mode']) {
finalParams['mode'] = params['mode'];
if (copiedParams['mode']) {
finalParams['mode'] = copiedParams['mode'];
}

if (params['language_id']) {
finalParams['language_id'] = params['language_id'];
if (copiedParams['language_id']) {
finalParams['language_id'] = copiedParams['language_id'];
}

if (params['variantName']) {
finalParams['variantName'] = params['variantName'];
if (copiedParams['variantName']) {
finalParams['variantName'] = copiedParams['variantName'];
}

if (params['personaId'] || dotMarketingPersonaId) {
finalParams['personaId'] = params['personaId'] || dotMarketingPersonaId;
if (copiedParams['personaId'] || dotMarketingPersonaId) {
finalParams['personaId'] = copiedParams['personaId'] || dotMarketingPersonaId;
}

return {
Expand Down
4 changes: 2 additions & 2 deletions core-web/libs/sdk/experiments/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dotcms/experiments",
"version": "0.0.1-alpha.35",
"version": "0.0.1-alpha.37",
"description": "Official JavaScript library to use Experiments with DotCMS.",
"repository": {
"type": "git",
Expand All @@ -25,6 +25,6 @@
"peerDependencies": {
"react": ">=18",
"react-dom": ">=18",
"@dotcms/client": "0.0.1-alpha.35"
"@dotcms/client": "0.0.1-alpha.37"
}
}
4 changes: 2 additions & 2 deletions core-web/libs/sdk/react/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@dotcms/react",
"version": "0.0.1-alpha.35",
"version": "0.0.1-alpha.37",
"peerDependencies": {
"react": ">=18",
"react-dom": ">=18",
"@dotcms/client": "0.0.1-alpha.35",
"@dotcms/client": "0.0.1-alpha.37",
"@tinymce/tinymce-react": "^5.1.1"
},
"description": "Official React Components library to render a dotCMS page.",
Expand Down
4 changes: 2 additions & 2 deletions examples/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"@angular/platform-browser": "^17.1.0",
"@angular/platform-browser-dynamic": "^17.1.0",
"@angular/router": "^17.1.0",
"@dotcms/angular": "0.0.1-alpha.35",
"@dotcms/client": "0.0.1-alpha.35",
"@dotcms/angular": "0.0.1-alpha.37",
"@dotcms/client": "0.0.1-alpha.37",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.2"
Expand Down
11 changes: 11 additions & 0 deletions examples/astro/.env.local.example
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



25 changes: 25 additions & 0 deletions examples/astro/.gitignore
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/
12 changes: 12 additions & 0 deletions examples/astro/.prettierrc.mjs
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",
},
},
],
};
50 changes: 50 additions & 0 deletions examples/astro/README.md
zJaaal marked this conversation as resolved.
Show resolved Hide resolved
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.
12 changes: 12 additions & 0 deletions examples/astro/astro.config.mjs
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(),
});
Loading
Loading