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

Handle email with Ghost #124

Merged
merged 3 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
109 changes: 109 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,112 @@ __pycache__/
# jupyter-book
/_build/
/conf.py
.vercel

### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### macOS template
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 5 additions & 9 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,8 @@ parse:
{{ '```{committers} ' + env.docname + '.md\n```' }}

<div id="email-modal" class="modal">
<iframe name="mailchimp-result" style="display: none;"></iframe>
<form
action="https://premai.us21.list-manage.com/subscribe/post?u=76d4e3f9cb2c0f0108fb2da88&amp;id=2c17a51111&amp;f_id=0014ede6f0"
method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="modal-content"
target="mailchimp-result" novalidate="">
<iframe name="ghost-result" style="display: none;"></iframe>
<form class="modal-content" method="post" action="https://state-of-open-source-ai.vercel.app/api/add-member" target="ghost-result" novalidate="">
<img src="https://static.premai.io/book/book-cover.jpg" alt="book cover" />
<div class="modal-text">
<h1>Enter your email to access this book for free</h1>
Expand All @@ -72,15 +69,14 @@ parse:
(no spam nor giving your email to anyone else).
</p>
<div class="input-container">
<input type="email" id="email-input" name="EMAIL" placeholder="Enter your email..." />
<input style="display: none;" type="hidden" name="tags" value="2958019" />
<input style="display: none;" type="text" name="b_76d4e3f9cb2c0f0108fb2da88_2c17a51111" tabindex="-1" value="" />
<input type="submit" name="subscribe" id="email-submit" class="button" value="Subscribe" onclick="emailButtonClick()" />
<input type="email" id="email-input" name="email" placeholder="Enter your email..." />
<button type="submit" id="email-submit" class="button" onclick="emailButtonClick()">Subscribe</button>
</div>
<p>
This book is open source; you can also read &amp; contribute at<br />
<a href="https://github.com/premAI-io/state-of-open-source-ai" target="_blank"><i class="fa-brands fa-github"></i>&nbsp;premAI-io/state-of-open-source-ai</a>.
</p>
<span class="email-error"></span>
</div>
</form>
</div>
Expand Down
2 changes: 2 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vercel
node_modules
24 changes: 24 additions & 0 deletions backend/api/add-member.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import jwt from 'jsonwebtoken';
import axios from 'axios';

export default async function handler(req, res) {
const BLOG_URL = "https://prem.ghost.io";
const [id, secret] = process.env.ADMIN_API_KEY.split(':');
const token = jwt.sign({}, Buffer.from(secret, 'hex'), {
keyid: id,
algorithm: 'HS256',
expiresIn: '5m',
audience: `/admin/`
});

const url = `${BLOG_URL}/ghost/api/admin/members/`;
const headers = { Authorization: `Ghost ${token}` };
const payload = { members: [{ email: req.body.email }] };

try {
const response = await axios.post(url, payload, { headers });
res.status(200).json(response.data);
} catch (error) {
res.status(500).json({ error: error.response.data.errors[0].message });
}
}
Loading
Loading