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

Refactor to allow for more flexibility and customization options in the future #45

Merged
merged 6 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions packages/studioCMS/src/components/Header.astro
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
// @ts-expect-error - This is a missing type definition for the `astro:db` import since its a virtual module during Astro Runtime
import { SiteConfig, db } from 'astro:db';
import Config from 'virtual:astro-studio-cms:config';
import Config from 'virtual:studiocms/config';
import profileImg from '../assets/profile.webp';
import type { Locals } from '../pages/dashboard/locals';
import type { Locals } from '../schemas/locals';
import HeaderLink from './HeaderLink.astro';

const {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
import { Image } from 'astro:assets';
import Config from 'virtual:astro-studio-cms:config';
import Config from 'virtual:studiocms/config';
import { Cloudinary } from '@cloudinary/url-gen';
import { fill } from '@cloudinary/url-gen/actions/resize';
import type { Locals } from '../pages/dashboard/locals';
import type { Locals } from '../../schemas/locals';

interface Props {
src: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
---
import Config from 'virtual:studiocms/config';

const { dateLocale: locales } = Config;

interface Props {
date: Date;
}
Expand All @@ -8,7 +12,7 @@ const { date } = Astro.props;

<time datetime={date.toISOString()}>
{
date.toLocaleDateString('en-us', {
date.toLocaleDateString(locales, {
year: 'numeric',
month: 'short',
day: 'numeric',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
import Config from 'virtual:studiocms/config';
import { renderMarkDoc } from '../../utils/markdoc';
import { renderMarked } from '../../utils/marked';

type Props = {
content: string;
};

const { content } = Astro.props;

function contentRenderer() {
if (Config.contentRenderer === 'markdoc') {
return renderMarkDoc(content);
}
return renderMarked(content);
}
---

<Fragment set:html={contentRenderer()} />
27 changes: 25 additions & 2 deletions packages/studioCMS/src/layouts/BlogIndex.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
// @ts-expect-error - This is a missing type definition for the `astro:db` import since its a virtual module during Astro Runtime
import { SiteConfig, Blog, asc, db } from 'astro:db';
import { SiteConfig, asc, db } from 'astro:db';
import Config from 'virtual:studiocms/config';
import BaseHead from '../components/BaseHead.astro';
import Footer from '../components/Footer.astro';
import Header from '../components/Header.astro';
Expand All @@ -12,9 +13,31 @@ type Props = {
title: string;
description: string;
heroImage?: string;
posts: []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
posts: []
posts: BlogPost[]

Copy link
Member Author

@Adammatthiesen Adammatthiesen May 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added in newest commit where i am now actually duplicating some of the astroDB runtime types for the DB tables. 🎉 and implemented your suggestion as well

};

const { title, description, heroImage } = Astro.props;
type BlogPost = {
slug: string;
title: string;
description: string;
heroImage: string;
publishedAt: Date;
updatedAt?: Date | null;
}

const { title, description, heroImage, posts } = Astro.props;

if (Config.includedIntegrations.useInoxSitemap) {
import('sitemap-ext:config').then((sitemap) => {
sitemap.default(async ({ addToSitemap }) => {
addToSitemap(
posts.map((post: BlogPost) => ({
slug: post.slug,
}))
);
});
})
}

const pageDescription = `${description} - ${contextConfig.description}`;
const pageTitle = `${title} | ${contextConfig.title}`;
Expand Down
19 changes: 11 additions & 8 deletions packages/studioCMS/src/layouts/BlogPost.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@
// @ts-expect-error - This is a missing type definition for the `astro:db` import since its a virtual module during Astro Runtime
import { SiteConfig, db } from 'astro:db';
import BaseHead from '../components/BaseHead.astro';
import CImage from '../components/CImage.astro';
import { CImage, FormattedDate } from 'studiocms:components';
import Footer from '../components/Footer.astro';
import FormattedDate from '../components/FormattedDate.astro';
import Header from '../components/Header.astro';

const ConfigArray = await db.select().from(SiteConfig);
const contextConfig = ConfigArray.pop();

type Props = {
title: string;
description: string;
heroImage: string;
publishedAt: Date;
updatedAt?: Date | null;
post: {
title: string;
description: string;
heroImage: string;
publishedAt: Date;
updatedAt?: Date | null;
}
};

const { title, description, publishedAt, updatedAt, heroImage } = Astro.props;
const { post } = Astro.props;
const { title, description, publishedAt, updatedAt, heroImage } = post;

---

<html lang="en">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
---
// @ts-expect-error - This is a missing type definition for the `astro:db` import since its a virtual module during Astro Runtime
import { Permissions, db, eq } from 'astro:db';
import Dashboard from '../../layouts/Dashboard.astro';
import { rankCheck } from '../../utils/rankcheck';
import type { Locals } from './locals';
import sitemap from 'sitemap-ext:config';
sitemap(false); // opt-out
import Dashboard from '../layouts/Dashboard.astro';
import { rankCheck } from '../utils/rankcheck';
import type { Locals } from '../schemas/locals';
import Config from 'virtual:studiocms/config';

if (Config.includedIntegrations.useInoxSitemap) {
import('sitemap-ext:config').then((sitemap) => {
sitemap.default(false)
})
}

function redirectToPath(path: string) {
return Astro.redirect(import.meta.env.BASE_URL + path);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
---
// @ts-expect-error - This is a missing type definition for the `astro:db` import since its a virtual module during Astro Runtime
import { Blog, db, eq } from 'astro:db';
import Dashboard from '../../../layouts/Dashboard.astro';
import { rankCheck } from '../../../utils/rankcheck';
import type { Locals } from '../locals';
import sitemap from 'sitemap-ext:config';
sitemap(false); // opt-out
import Dashboard from '../../layouts/Dashboard.astro';
import { rankCheck } from '../../utils/rankcheck';
import type { Locals } from '../../schemas/locals';
import Config from 'virtual:studiocms/config';

if (Config.includedIntegrations.useInoxSitemap) {
import('sitemap-ext:config').then((sitemap) => {
sitemap.default(false)
})
}

function redirectToPath(path: string) {
return Astro.redirect(import.meta.env.BASE_URL + path);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
---
// @ts-expect-error - This is a missing type definition for the `astro:db` import since its a virtual module during Astro Runtime
import { Blog, db, eq } from 'astro:db';
import Dashboard from '../../../layouts/Dashboard.astro';
import { rankCheck } from '../../../utils/rankcheck';
import type { Locals } from '../locals';
import sitemap from 'sitemap-ext:config';
sitemap(false); // opt-out
import Dashboard from '../../layouts/Dashboard.astro';
import { rankCheck } from '../../utils/rankcheck';
import type { Locals } from '../../schemas/locals';
import Config from 'virtual:studiocms/config';

if (Config.includedIntegrations.useInoxSitemap) {
import('sitemap-ext:config').then((sitemap) => {
sitemap.default(false)
})
}

function redirectToPath(path: string) {
return Astro.redirect(import.meta.env.BASE_URL + path);
Expand Down Expand Up @@ -131,19 +136,24 @@ if (Astro.request.method === 'POST') {
</Dashboard>

<script>
import { markdown } from "../../../utils/marked";
import Config from 'virtual:astro-studio-cms:config';
import { renderMarkDoc } from '../../../utils/markdoc';
import Config from 'virtual:studiocms/config';
import { renderMarked } from "../../utils/marked";
import { renderMarkDoc } from '../../utils/markdoc';

//@ts-ignore
document.getElementById('content').addEventListener('input', async function () {
const markdownContent = document.getElementById('content');
const htmlPreview = document.getElementById('html-preview');

if (Config.contentRenderer === 'marked' ) {
const htmlContent = await markdown(markdownContent.value);
//@ts-ignore
const htmlContent = await renderMarked(markdownContent.value);
//@ts-ignore
htmlPreview.innerHTML = htmlContent;
} else if (Config.contentRenderer === 'markdoc') {
//@ts-ignore
const htmlContent = await renderMarkDoc(markdownContent.value);
//@ts-ignore
Comment on lines +146 to +153
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the issue with ts here?

htmlPreview.innerHTML = htmlContent;
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
---
// @ts-expect-error - This is a missing type definition for the `astro:db` import since its a virtual module during Astro Runtime
import { Pages, db, eq } from 'astro:db';
import Dashboard from '../../../layouts/Dashboard.astro';
import { rankCheck } from '../../../utils/rankcheck';
import type { Locals } from '../locals';
import sitemap from 'sitemap-ext:config';
sitemap(false); // opt-out
import Dashboard from '../../layouts/Dashboard.astro';
import { rankCheck } from '../../utils/rankcheck';
import type { Locals } from '../../schemas/locals';
import Config from 'virtual:studiocms/config';

if (Config.includedIntegrations.useInoxSitemap) {
import('sitemap-ext:config').then((sitemap) => {
sitemap.default(false)
})
}

const postArrayed = await db.select().from(Pages).where(eq(Pages.slug, 'about'));
const post = postArrayed[0];
Expand Down Expand Up @@ -124,19 +129,24 @@ if (Astro.request.method === 'POST') {
</Dashboard>

<script>
import { markdown } from "../../../utils/marked";
import Config from 'virtual:astro-studio-cms:config';
import { renderMarkDoc } from '../../../utils/markdoc';
import Config from 'virtual:studiocms/config';
import { renderMarked } from "../../utils/marked";
import { renderMarkDoc } from '../../utils/markdoc';

//@ts-ignore
document.getElementById('content').addEventListener('input', async function () {
const markdownContent = document.getElementById('content');
const htmlPreview = document.getElementById('html-preview');

if (Config.contentRenderer === 'marked' ) {
const htmlContent = await markdown(markdownContent.value);
//@ts-ignore
const htmlContent = await renderMarked(markdownContent.value);
//@ts-ignore
htmlPreview.innerHTML = htmlContent;
} else if (Config.contentRenderer === 'markdoc') {
//@ts-ignore
const htmlContent = await renderMarkDoc(markdownContent.value);
//@ts-ignore
Comment on lines +140 to +147
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question here

htmlPreview.innerHTML = htmlContent;
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
---
// @ts-expect-error - This is a missing type definition for the `astro:db` import since its a virtual module during Astro Runtime
import { Admins, Pages, db, eq } from 'astro:db';
import Dashboard from '../../../layouts/Dashboard.astro';
import { rankCheck } from '../../../utils/rankcheck';
import type { Locals } from '../locals';
import sitemap from 'sitemap-ext:config';
sitemap(false); // opt-out
import Dashboard from '../../layouts/Dashboard.astro';
import { rankCheck } from '../../utils/rankcheck';
import type { Locals } from '../../schemas/locals';
import Config from 'virtual:studiocms/config';

if (Config.includedIntegrations.useInoxSitemap) {
import('sitemap-ext:config').then((sitemap) => {
sitemap.default(false)
})
}

const postArrayed = await db.select().from(Pages).where(eq(Pages.slug, 'index'));
const post = postArrayed[0];
Expand Down Expand Up @@ -125,19 +130,24 @@ if (Astro.request.method === 'POST') {
</Dashboard>

<script>
import { markdown } from "../../../utils/marked";
import Config from 'virtual:astro-studio-cms:config';
import { renderMarkDoc } from '../../../utils/markdoc';
import Config from 'virtual:studiocms/config';
import { renderMarked } from "../../utils/marked";
import { renderMarkDoc } from '../../utils/markdoc';

//@ts-ignore
document.getElementById('content').addEventListener('input', async function () {
const markdownContent = document.getElementById('content');
const htmlPreview = document.getElementById('html-preview');

if (Config.contentRenderer === 'marked' ) {
const htmlContent = await markdown(markdownContent.value);
//@ts-ignore
const htmlContent = await renderMarked(markdownContent.value);
//@ts-ignore
htmlPreview.innerHTML = htmlContent;
} else if (Config.contentRenderer === 'markdoc') {
//@ts-ignore
const htmlContent = await renderMarkDoc(markdownContent.value);
//@ts-ignore
Comment on lines +140 to +147
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, here as well.

htmlPreview.innerHTML = htmlContent;
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
---
import Dashboard from '../../layouts/Dashboard.astro';
import { rankCheck } from '../../utils/rankcheck';
import type { Locals } from './locals';
import sitemap from 'sitemap-ext:config';
sitemap(false); // opt-out
import Dashboard from '../layouts/Dashboard.astro';
import { rankCheck } from '../utils/rankcheck';
import type { Locals } from '../schemas/locals';
import Config from 'virtual:studiocms/config';

if (Config.includedIntegrations.useInoxSitemap) {
import('sitemap-ext:config').then((sitemap) => {
sitemap.default(false)
})
}

const locals = Astro.locals as Locals;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { User, db, eq } from 'astro:db';
import { GitHub, OAuth2RequestError } from 'arctic';
import type { APIContext } from 'astro';
import { lucia } from '../../../../lib/auth';
import { lucia } from '../../../lib/auth';

export async function GET(context: APIContext): Promise<Response> {
const {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
---
import Layout from '../../../layouts/Default.astro';
import type { Locals } from '../locals';
import sitemap from 'sitemap-ext:config';
sitemap(false); // opt-out
import Layout from '../../layouts/Default.astro';
import type { Locals } from '../../schemas/locals';
import Config from 'virtual:studiocms/config';

if (Config.includedIntegrations.useInoxSitemap) {
import('sitemap-ext:config').then((sitemap) => {
sitemap.default(false)
})
}

const locals = Astro.locals as Locals;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { APIContext } from 'astro';
import { lucia } from '../../lib/auth';
import { lucia } from '../lib/auth';

export async function GET(context: APIContext): Promise<Response> {
return context.redirect(import.meta.env.BASE_URL);
Expand Down
Loading