Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
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
5 changes: 5 additions & 0 deletions .changeset/every-seas-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@studiocms/socialposter": patch
---

Initial release
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
"alignjustify",
"alignleft",
"alignright",
"astroenv",
"atproto",
"Avenir",
"backcolor",
"bsky",
"bullist",
"cmdm",
"CMSWYSIWYG",
Expand All @@ -19,10 +22,12 @@
"numlist",
"outdent",
"projectdata",
"socialposter",
"strikethrough",
"studiocms",
"studiosdk",
"toastr",
"virtuals",
"withstudiocms",
"WYSIWYGDB"
]
Expand Down
23 changes: 23 additions & 0 deletions packages/studiocms_socialposter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

# generated types
.astro/

# dependencies
node_modules/

# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# environment variables
.env
.env.production

# macOS-specific files
.DS_Store

.npmrc

dist/
21 changes: 21 additions & 0 deletions packages/studiocms_socialposter/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 StudioCMS - Adam Matthiesen, Jacob Jenkins, Paul Valladares

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
48 changes: 48 additions & 0 deletions packages/studiocms_socialposter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# @StudioCMS/socialposter Plugin

Allow cross-posting to your social media accounts from your StudioCMS dashboard with ease!

## Requirements

Depending on which services you are trying to post on you may require one of more of the following variables in your `.env`

```bash
# Twitter/X
TWITTER_API_KEY=your_api_key
TWITTER_API_SECRET=your_api_secret
TWITTER_ACCESS_TOKEN=your_access_token
TWITTER_ACCESS_SECRET=your_access_secret

# Bluesky
BLUESKY_SERVICE=https://bsky.social
BLUESKY_USERNAME=your_username
BLUESKY_PASSWORD=your_password

# Threads/Instagram
THREADS_USER_ID=your_user_id
THREADS_ACCESS_TOKEN=your_access_token
```

### Usage

Add this plugin in your StudioCMS config (`studiocms.config.mjs`) and enable the desired options.

```ts
import { defineStudioCMSConfig } from 'studiocms/config';
import socialPoster from '@studiocms/socialposter';

export default defineStudioCMSConfig({
// other options here
plugins: [
socialPoster({
bluesky: false,
threads: false,
twitter: false,
})
],
});
```

## License

[MIT Licensed](./LICENSE).
11 changes: 11 additions & 0 deletions packages/studiocms_socialposter/astroenv.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare module 'astro:env/server' {
export const TWITTER_API_KEY: string | undefined;
export const TWITTER_API_SECRET: string | undefined;
export const TWITTER_ACCESS_TOKEN: string | undefined;
export const TWITTER_ACCESS_SECRET: string | undefined;
export const BLUESKY_SERVICE: string | undefined;
export const BLUESKY_USERNAME: string | undefined;
export const BLUESKY_PASSWORD: string | undefined;
export const THREADS_USER_ID: string | undefined;
export const THREADS_ACCESS_TOKEN: string | undefined;
}
63 changes: 63 additions & 0 deletions packages/studiocms_socialposter/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "@studiocms/socialposter",
"version": "0.1.0-experimental.0",
"description": "Allow cross-posting to your social media accounts from your StudioCMS dashboard with ease!",
"author": {
"name": "Adam Matthiesen | Jacob Jenkins | Paul Valladares",
"url": "https://studiocms.dev"
},
"repository": {
"type": "git",
"url": "git+https://github.com/withstudiocms/experiments.git",
"directory": "packages/studiocms_socialposter"
},
"contributors": ["Adammatthiesen", "jdtjenkins", "dreyfus92", "code.spirit"],
"license": "MIT",
"keywords": [
"astro",
"astrocms",
"astrodb",
"astrostudio",
"astro-integration",
"astro-studio",
"astro-studiocms",
"cms",
"studiocms",
"withastro",
"plugin",
"studiocms-plugin"
],
"homepage": "https://studiocms.dev",
"publishConfig": {
"access": "public",
"provenance": true
},
"sideEffects": false,
"files": ["dist"],
"scripts": {
"build": "build-scripts build 'src/**/*.{ts,astro,css,js}'",
"dev": "build-scripts dev 'src/**/*.{ts,astro,css,js}'"
},
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"type": "module",
"dependencies": {
"@atproto/api": "^0.14.20",
"@studiocms/ui": "^0.4.16",
"astro-integration-kit": "catalog:",
"twitter-api-v2": "^1.22.0",
"quill": "^2.0.3"
},
"devDependencies": {
"@types/node": "catalog:"
},
"peerDependencies": {
"astro": "catalog:min",
"studiocms": "catalog:min",
"vite": "catalog:min"
}
}
151 changes: 151 additions & 0 deletions packages/studiocms_socialposter/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/**
* These triple-slash directives defines dependencies to various declaration files that will be
* loaded when a user imports the StudioCMS plugin in their Astro configuration file. These
* directives must be first at the top of the file and can only be preceded by this comment.
*/
/// <reference types="./virtuals.d.ts" preserve="true" />
/// <reference types="../astroenv.d.ts" />
/// <reference types="../ui.d.ts" />
/// <reference types="studiocms/v/types" />
import { addVirtualImports, createResolver } from 'astro-integration-kit';
import { type StudioCMSPlugin, definePlugin } from 'studiocms/plugins';
import { addAstroEnvConfig } from './utils/astroEnvConfig.js';
import { envField } from 'astro/config';

export interface StudioCMSSocialPosterOptions {
bluesky: boolean;
threads: boolean;
twitter: boolean;
}

const defaultOptions: StudioCMSSocialPosterOptions = {
bluesky: false,
threads: false,
twitter: false,
};

function studiocmsSocialPoster(opts?: Partial<StudioCMSSocialPosterOptions>): StudioCMSPlugin {
// Resolve the path to the current file
const { resolve } = createResolver(import.meta.url);

// Define the package identifier
const packageIdentifier = '@studiocms/socialposter';

const options: StudioCMSSocialPosterOptions = {
...defaultOptions,
...opts,
};

return definePlugin({
identifier: packageIdentifier,
name: 'StudioCMS Social Poster',
studiocmsMinimumVersion: '0.1.0-beta.14',
dashboardPages: {
user: [
{
title: {
'en-us': 'Share to Social Media',
},
description: 'Share content on Social media',
sidebar: 'single',
pageBodyComponent: resolve('./pages/socials.astro'),
route: 'share',
requiredPermissions: 'editor',
icon: 'share',
},
],
},
integration: {
name: packageIdentifier,
hooks: {
'astro:config:setup': (params) => {
const { injectRoute } = params;

addAstroEnvConfig(params, {
validateSecrets: true,
schema: {
BLUESKY_SERVICE: envField.string({
context: 'server',
access: 'secret',
optional: !options.bluesky,
}),
BLUESKY_USERNAME: envField.string({
context: 'server',
access: 'secret',
optional: !options.bluesky,
}),
BLUESKY_PASSWORD: envField.string({
context: 'server',
access: 'secret',
optional: !options.bluesky,
}),
THREADS_USER_ID: envField.string({
context: 'server',
access: 'secret',
optional: !options.threads,
}),
THREADS_ACCESS_TOKEN: envField.string({
context: 'server',
access: 'secret',
optional: !options.threads,
}),
TWITTER_API_KEY: envField.string({
context: 'server',
access: 'secret',
optional: !options.twitter,
}),
TWITTER_API_SECRET: envField.string({
context: 'server',
access: 'secret',
optional: !options.twitter,
}),
TWITTER_ACCESS_TOKEN: envField.string({
context: 'server',
access: 'secret',
optional: !options.twitter,
}),
TWITTER_ACCESS_SECRET: envField.string({
context: 'server',
access: 'secret',
optional: !options.twitter,
}),
},
});

addVirtualImports(params, {
name: packageIdentifier,
imports: {
'studiocms:socialposter/config': `export default ${JSON.stringify(options)}`,
},
});

if (options.bluesky) {
injectRoute({
pattern: '/studiocms_api/socialposter/post-to-bluesky',
entrypoint: resolve('./routes/postToBlueSky.js'),
prerender: false,
});
}

if (options.threads) {
injectRoute({
pattern: '/studiocms_api/socialposter/post-to-threads',
entrypoint: resolve('./routes/postToThreads.js'),
prerender: false,
});
}

if (options.twitter) {
injectRoute({
pattern: '/studiocms_api/socialposter/post-to-twitter',
entrypoint: resolve('./routes/postToTwitter.js'),
prerender: false,
});
}
},
},
},
});
}

export default studiocmsSocialPoster;
Loading