@studiocms/blog 0.1.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Astrolicious - StudioCMS - Adam Matthiesen, Jacob Jenkins, Paul Valladares
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # StudioCMS - Blog Provider
package/index.ts ADDED
@@ -0,0 +1,65 @@
1
+ import { defineStudioCMSPlugin } from '@studiocms/core/lib';
2
+ import defineTheme from 'astro-theme-provider';
3
+ import { name } from './package.json';
4
+ import { studioCMSBlogSchema as schema } from './schema';
5
+
6
+ const studioCMSBlogTheme = defineTheme({
7
+ name,
8
+ schema,
9
+ });
10
+
11
+ /**
12
+ * User definable options for the StudioCMS Blog Theme
13
+ */
14
+ export type ATP_ThemeOptions = Parameters<typeof studioCMSBlogTheme>[0];
15
+
16
+ /**
17
+ * # StudioCMS Blog Theme(Integration)
18
+ * #### Powered by [`astro-theme-provider`](https://github.com/astrolicious/astro-theme-provider) by [Bryce Russell](https://github.com/BryceRussell)
19
+ *
20
+ * This theme provides a Blog Index Page and RSS Feed for your StudioCMS Site as well as route handling for Blog Posts.
21
+ *
22
+ * @example
23
+ * import { defineConfig } from 'astro/config';
24
+ * import db from '@astrojs/db';
25
+ * import studioCMS from 'studiocms';
26
+ * import studioCMSBlog from '@studiocms/blog';
27
+ *
28
+ * // https://astro.build/config
29
+ * export default defineConfig({
30
+ * site: "https://example.com",
31
+ * output: "server",
32
+ * adapter: ...
33
+ * integrations: [
34
+ * db(), // REQUIRED - `@astrojs/db` must be included in the integrations list
35
+ * studioCMS(), // REQUIRED - StudioCMS must be included in the integrations list
36
+ * studioCMSBlog({
37
+ * config: {
38
+ * title: "My StudioCMS Blog",
39
+ * description: "A Simple Blog build with Astro, Astrojs/DB, and StudioCMS.".
40
+ * },
41
+ * }),
42
+ * ],
43
+ * });
44
+ */
45
+ export function studioCMSBlog(options: ATP_ThemeOptions) {
46
+ let slug: string;
47
+
48
+ if (typeof options?.pages?.['/blog'] === 'string') {
49
+ slug = options.pages['/blog'];
50
+ } else {
51
+ slug = 'blog/';
52
+ }
53
+
54
+ defineStudioCMSPlugin({
55
+ pkgname: name,
56
+ opts: {
57
+ pluginLabel: 'StudioCMS Blog',
58
+ navigationLinks: [{ text: 'Blog', slug: slug }],
59
+ },
60
+ });
61
+
62
+ return studioCMSBlogTheme(options);
63
+ }
64
+
65
+ export default studioCMSBlog;
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@studiocms/blog",
3
+ "version": "0.1.0-beta.5",
4
+ "description": "Add a blog to your StudioCMS project with ease!",
5
+ "author": {
6
+ "name": "Adam Matthiesen | Jacob Jenkins | Paul Valladares",
7
+ "url": "https://astro-studiocms.xyz"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/astrolicious/studiocms.git"
12
+ },
13
+ "contributors": [
14
+ "Adammatthiesen",
15
+ "jdtjenkins",
16
+ "dreyfus92"
17
+ ],
18
+ "license": "MIT",
19
+ "keywords": [
20
+ "astro",
21
+ "astrocms",
22
+ "astrodb",
23
+ "astrolicious",
24
+ "astrostudio",
25
+ "astro-integration",
26
+ "astro-studio",
27
+ "astro-studiocms",
28
+ "cms",
29
+ "studiocms",
30
+ "withastro",
31
+ "blog",
32
+ "studio-blog",
33
+ "astro-blog",
34
+ "astro-studio-blog",
35
+ "studiocms-blog",
36
+ "theme",
37
+ "astro-theme",
38
+ "studiocms-theme",
39
+ "astro-studiocms-theme"
40
+ ],
41
+ "homepage": "https://astro-studiocms.xyz",
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "sideEffects": false,
46
+ "files": [
47
+ "index.ts",
48
+ "schema.ts",
49
+ "src"
50
+ ],
51
+ "exports": {
52
+ ".": "./index.ts",
53
+ "./schema": "./schema.ts"
54
+ },
55
+ "type": "module",
56
+ "dependencies": {
57
+ "@astrojs/rss": "^4.0.7",
58
+ "astro-theme-provider": "^0.6.1",
59
+ "@studiocms/core": "0.1.0-beta.5",
60
+ "@studiocms/frontend": "0.1.0-beta.5"
61
+ },
62
+ "devDependencies": {
63
+ "@types/node": "^20.14.11"
64
+ },
65
+ "peerDependencies": {
66
+ "astro": ">=4.15"
67
+ }
68
+ }
package/schema.ts ADDED
@@ -0,0 +1,35 @@
1
+ import { z } from 'astro/zod';
2
+
3
+ /**
4
+ * StudioCMS Blog Schema
5
+ */
6
+ export const studioCMSBlogSchema = z.object({
7
+ /**
8
+ * Title to be used in the RSS Feed.
9
+ */
10
+ title: z.string().optional(),
11
+ /**
12
+ * Description to be used in the RSS Feed.
13
+ */
14
+ description: z.string().optional(),
15
+ /**
16
+ * Allows for the configuration of the Blog Index Page.
17
+ */
18
+ blogIndex: z
19
+ .object({
20
+ /**
21
+ * Title to use for the Blog Index Page.
22
+ */
23
+ title: z.string().optional().default('Blog'),
24
+ /**
25
+ * Whether to show the RSS Feed URL on the Blog Index Page.
26
+ */
27
+ showRSSFeed: z.boolean().optional().default(true),
28
+ })
29
+ .optional(),
30
+ });
31
+
32
+ /**
33
+ * StudioCMS Blog Schema Type
34
+ */
35
+ export type StudioCMSBlogSchema = z.infer<typeof studioCMSBlogSchema>;
@@ -0,0 +1,131 @@
1
+ ---
2
+ import { pages } from '@studiocms/blog:context';
3
+ import { FormattedDate } from 'studiocms:components';
4
+ import { pathWithBase } from 'studiocms:helpers';
5
+ import type { pageDataReponse } from 'studiocms:helpers/contentHelper';
6
+ import { CustomImage } from 'studiocms:imageHandler/components';
7
+
8
+ const blogRouteFullPath = pages.get('/blog/[...slug]');
9
+
10
+ function getBlogRoute(slug: string) {
11
+ if (blogRouteFullPath) {
12
+ return blogRouteFullPath.replace('[...slug]', slug);
13
+ }
14
+ return '#';
15
+ }
16
+
17
+ interface Props {
18
+ blogPageList: pageDataReponse[];
19
+ }
20
+
21
+ const { blogPageList } = Astro.props;
22
+ ---
23
+
24
+ <ul>
25
+ {
26
+ blogPageList.length > 0 && blogPageList.map(({slug, heroImage, title, description, publishedAt}) => (
27
+ <li>
28
+ <a href={pathWithBase(getBlogRoute(slug))}>
29
+ <CustomImage src={heroImage} alt={title} width={720} height={360}/>
30
+ <div>
31
+ <span class="title">{title}</span>
32
+ <span class="date"> <FormattedDate date={publishedAt} /> </span>
33
+ </div>
34
+
35
+ <p class="description">
36
+ {description}
37
+ </p>
38
+ </a>
39
+ </li>
40
+ ))
41
+ }
42
+
43
+ {
44
+ blogPageList.length === 0 && <li>No blog posts found</li>
45
+ }
46
+ </ul>
47
+
48
+ <style>
49
+ ul {
50
+ display: flex;
51
+ flex-wrap: wrap;
52
+ gap: 2rem;
53
+ list-style-type: none;
54
+ margin: 0;
55
+ padding: 0;
56
+ }
57
+ ul li {
58
+ width: calc(50% - 1rem);
59
+ }
60
+ ul li * {
61
+ text-decoration: none;
62
+ transition: 0.2s ease;
63
+ }
64
+ ul li:first-child {
65
+ width: 100%;
66
+ margin-bottom: 1rem;
67
+ text-align: center;
68
+ }
69
+ ul li:first-child img {
70
+ width: 100%;
71
+ }
72
+ ul li:first-child .title {
73
+ font-size: 2.369rem;
74
+ }
75
+ ul li img {
76
+ margin-bottom: 0.5rem;
77
+ border-radius: 12px;
78
+ }
79
+ ul li a {
80
+ display: block;
81
+ }
82
+ .title {
83
+ margin: 0;
84
+ color: rgb(var(--black));
85
+ font: bold;
86
+ font-weight: bold;
87
+ line-height: 1;
88
+ display: inline;
89
+ }
90
+ .date {
91
+ margin: 0;
92
+ color: rgb(var(--gray));
93
+ font: normal;
94
+ line-height: normal;
95
+ display: inline;
96
+ }
97
+ .description {
98
+ margin: 0;
99
+ color: rgb(var(--black));
100
+ width: 720px;
101
+ display: -webkit-box;
102
+ -webkit-box-orient: vertical;
103
+ -webkit-line-clamp: 2;
104
+ overflow: hidden;
105
+ }
106
+ ul li a:hover span,
107
+ ul li a:hover .date {
108
+ color: rgb(var(--accent));
109
+ }
110
+ ul a:hover img {
111
+ box-shadow: var(--box-shadow);
112
+ }
113
+ @media (max-width: 720px) {
114
+ ul {
115
+ gap: 0.5em;
116
+ }
117
+ ul li {
118
+ width: 100%;
119
+ text-align: center;
120
+ }
121
+ ul li:first-child {
122
+ margin-bottom: 0;
123
+ }
124
+ ul li:first-child .title {
125
+ font-size: 1.563em;
126
+ }
127
+ ul li:first-child .description {
128
+ width: 100%;
129
+ }
130
+ }
131
+ </style>
@@ -0,0 +1,46 @@
1
+ ---
2
+ import { FormattedDate } from 'studiocms:components';
3
+ import { CustomImage } from 'studiocms:imageHandler/components';
4
+
5
+ interface Props {
6
+ title: string;
7
+ publishedAt: Date;
8
+ updatedAt?: Date | null;
9
+ heroImage: string;
10
+ description: string;
11
+ }
12
+
13
+ const { title, description, heroImage, publishedAt, updatedAt } = Astro.props;
14
+ ---
15
+ <h1 class="title">{title}</h1>
16
+
17
+ <div style="text-align: center;">
18
+ <CustomImage src={heroImage} alt={title} width={720} height={360}/>
19
+ <div>
20
+ <p class="date">Published: <FormattedDate date={publishedAt}/></p>
21
+ {updatedAt && <p class="date"> | Last Updated: <FormattedDate date={updatedAt}/></p>}
22
+ </div>
23
+ <p class="description">{description}</p>
24
+ </div>
25
+
26
+ <style>
27
+ .title {
28
+ margin: 0;
29
+ color: rgb(var(--black));
30
+ font: bold;
31
+ font-weight: bold;
32
+ line-height: 1;
33
+ }
34
+ .date {
35
+ margin: 0;
36
+ color: rgb(var(--gray));
37
+ font: normal;
38
+ line-height: normal;
39
+ display: inline;
40
+ }
41
+ .description {
42
+ margin: 0;
43
+ color: rgb(var(--gray));
44
+ width: 720px;
45
+ }
46
+ </style>
@@ -0,0 +1,6 @@
1
+ ---
2
+ const props = Astro.props;
3
+ ---
4
+ <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" {...props}>
5
+ <path fill="currentColor" d="M6.18 15.64a2.18 2.18 0 0 1 2.18 2.18C8.36 19 7.38 20 6.18 20C5 20 4 19 4 17.82a2.18 2.18 0 0 1 2.18-2.18M4 4.44A15.56 15.56 0 0 1 19.56 20h-2.83A12.73 12.73 0 0 0 4 7.27zm0 5.66a9.9 9.9 0 0 1 9.9 9.9h-2.83A7.07 7.07 0 0 0 4 12.93z" />
6
+ </svg>
@@ -0,0 +1,39 @@
1
+ ---
2
+ import config from '@studiocms/blog:config';
3
+ import { Layout as FrontLayout } from '@studiocms/frontend/components';
4
+
5
+ interface Props {
6
+ title: string;
7
+ description: string;
8
+ lang?: string | undefined;
9
+ heroImage?: string;
10
+ siteTitle?: string;
11
+ siteDescription?: string;
12
+ pageTitleDelimiter?: string;
13
+ pageDescriptionDelimiter?: string;
14
+ }
15
+
16
+ const {
17
+ title,
18
+ description,
19
+ heroImage,
20
+ lang,
21
+ pageDescriptionDelimiter,
22
+ pageTitleDelimiter,
23
+ siteDescription = config.description,
24
+ siteTitle,
25
+ } = Astro.props;
26
+ ---
27
+
28
+ <FrontLayout
29
+ {title}
30
+ {description}
31
+ {siteTitle}
32
+ {siteDescription}
33
+ {lang}
34
+ {heroImage}
35
+ {pageDescriptionDelimiter}
36
+ {pageTitleDelimiter}
37
+ >
38
+ <slot />
39
+ </FrontLayout>
@@ -0,0 +1,40 @@
1
+ ---
2
+ import { PostHeader } from '@studiocms:blog/components';
3
+ import { BlogLayout } from '@studiocms:blog/layouts';
4
+ import { contentHelper } from 'studiocms:helpers/contentHelper';
5
+ import { StudioCMSRenderer } from 'studiocms:renderer';
6
+ import { name } from '../../../package.json';
7
+
8
+ // Get the slug from the URL
9
+ const { slug } = Astro.params;
10
+
11
+ // If no slug is provided, redirect to 404
12
+ if (!slug) {
13
+ return new Response(null, { status: 404 });
14
+ }
15
+
16
+ // Fetch the blog post content
17
+ const { id, title, description, heroImage, publishedAt, updatedAt, content } = await contentHelper(
18
+ slug,
19
+ name
20
+ );
21
+
22
+ // If no content is found, redirect to 404
23
+ if (!id) {
24
+ return new Response(null, { status: 404 });
25
+ }
26
+ ---
27
+ <BlogLayout {title} {description} {heroImage}>
28
+ <main>
29
+ <article>
30
+ <PostHeader {title} {description} {heroImage} {publishedAt} {updatedAt} />
31
+ <StudioCMSRenderer {content} />
32
+ </article>
33
+ </main>
34
+ </BlogLayout>
35
+
36
+ <style>
37
+ main {
38
+ width: 960px;
39
+ }
40
+ </style>
@@ -0,0 +1,38 @@
1
+ ---
2
+ import config from '@studiocms/blog:config';
3
+ import { pages } from '@studiocms/blog:context';
4
+ import { PageList, RSSIcon } from '@studiocms:blog/components';
5
+ import { BlogLayout } from '@studiocms:blog/layouts';
6
+ import { getPageList } from 'studiocms:helpers/contentHelper';
7
+ import { name } from '../../../package.json';
8
+
9
+ // Set the title and description
10
+ const { description: configDescription, blogIndex } = config;
11
+
12
+ const title: string = blogIndex?.title || 'Blog';
13
+ const description: string = configDescription || 'Blog Index';
14
+ const showRSSFeed: boolean = blogIndex?.showRSSFeed || true;
15
+
16
+ // Get all pages
17
+ const pageList = await getPageList();
18
+
19
+ // Get the RSS feed URL
20
+ const rssPath = pages.get('/rss.xml');
21
+
22
+ // Get all blog pages and sort by published date
23
+ const blogPageList = pageList
24
+ .filter((page) => page.package === name)
25
+ .sort((a, b) => Date.parse(b.publishedAt.toString()) - Date.parse(a.publishedAt.toString()));
26
+ ---
27
+ <BlogLayout {title} description={description} >
28
+ <main>
29
+ <h1>{title} {showRSSFeed && rssPath && <a href={rssPath}><RSSIcon /></a>}</h1>
30
+ <PageList {blogPageList} />
31
+ </main>
32
+ </BlogLayout>
33
+
34
+ <style>
35
+ main {
36
+ width: 960px;
37
+ }
38
+ </style>
@@ -0,0 +1,60 @@
1
+ import config from '@studiocms/blog:config';
2
+ import { pages } from '@studiocms/blog:context';
3
+ import { pathWithBase } from 'studiocms:helpers';
4
+ import { contentHelper, getPageList, getSiteConfig } from 'studiocms:helpers/contentHelper';
5
+ import { StudioCMSRenderer } from 'studiocms:renderer';
6
+ import rss from '@astrojs/rss';
7
+ import type { APIContext } from 'astro';
8
+ import { name } from '../../package.json';
9
+
10
+ import { experimental_AstroContainer as AstroContainer } from 'astro/container';
11
+
12
+ const blogRouteFullPath = pages.get('/blog/[...slug]');
13
+
14
+ function getBlogRoute(slug: string) {
15
+ if (blogRouteFullPath) {
16
+ return blogRouteFullPath.replace('[...slug]', slug);
17
+ }
18
+ return '#';
19
+ }
20
+
21
+ export async function GET(context: APIContext) {
22
+ // Get Config from Studio Database
23
+ const studioCMSConfig = await getSiteConfig();
24
+
25
+ // Set Title, Description, and Site
26
+ const title = config.title ?? studioCMSConfig.title;
27
+ const description = config.description ?? studioCMSConfig.description;
28
+ const site = context.site ?? 'https://example.com';
29
+
30
+ // Get all Posts from Studio Database
31
+ const unorderedPosts = await getPageList();
32
+
33
+ // Order Posts by Published Date
34
+ const orderedPosts = unorderedPosts
35
+ .filter((page) => page.package === name)
36
+ .sort((a, b) => Date.parse(b.publishedAt.toString()) - Date.parse(a.publishedAt.toString()));
37
+
38
+ // Render Known Posts
39
+ const items = await Promise.all(
40
+ orderedPosts.map(async ({ slug, title, description, publishedAt: pubDate, package: pkg }) => {
41
+ const { content: fetchedContent } = await contentHelper(slug, pkg);
42
+ const container = await AstroContainer.create();
43
+ const renderedContent = await container.renderToString(StudioCMSRenderer, {
44
+ props: { content: fetchedContent },
45
+ });
46
+
47
+ const content = renderedContent
48
+ .replace(/<!DOCTYPE html>/, '')
49
+ .replace(/<html.*?>/, '')
50
+ .replace(/<\/html>/, '')
51
+ .trim();
52
+
53
+ const link = pathWithBase(getBlogRoute(slug));
54
+
55
+ return { title, description, pubDate, content, link };
56
+ })
57
+ );
58
+
59
+ return rss({ title, description, site, items });
60
+ }