refactor(api-key): Inject Ghost API key at build time
This commit is contained in:
@@ -16,9 +16,11 @@ jobs:
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
cache: 'pnpm'
|
||||
- name: Install dependencies
|
||||
run: pnpm install
|
||||
- name: Create Ghost Config
|
||||
run: |
|
||||
echo "window.GhostConfig = { ghostApiKey: '${{ secrets.GHOST_CONTENT_API_KEY }}', ghostApiUrl: '${{ secrets.GHOST_ADMIN_API_URL }}' };" > assets/js/ghost-config.js
|
||||
- name: Build theme
|
||||
run: pnpm build
|
||||
- name: Deploy Ghost Theme
|
||||
|
||||
@@ -102,16 +102,14 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
let isLoading = false;
|
||||
let hasMorePosts = true;
|
||||
|
||||
const ghostApiKeyMeta = document.querySelector('meta[name="ghost-api-key"]');
|
||||
const ghostApiUrlMeta = document.querySelector('meta[name="ghost-api-url"]');
|
||||
|
||||
if (!ghostApiKeyMeta || !ghostApiUrlMeta) {
|
||||
console.error('Ghost Content API Key or URL meta tag not found. Infinite scroll will not work.');
|
||||
// Retrieve API key and URL from global GhostConfig object
|
||||
if (typeof window.GhostConfig === 'undefined' || !window.GhostConfig.ghostApiKey || !window.GhostConfig.ghostApiUrl) {
|
||||
console.error('Ghost Content API Key or URL not found in window.GhostConfig. Infinite scroll will not work.');
|
||||
return;
|
||||
}
|
||||
|
||||
const GHOST_API_KEY = ghostApiKeyMeta.content;
|
||||
const GHOST_API_URL = ghostApiUrlMeta.content;
|
||||
const GHOST_API_KEY = window.GhostConfig.ghostApiKey;
|
||||
const GHOST_API_URL = window.GhostConfig.ghostApiUrl;
|
||||
|
||||
const fetchPosts = async () => {
|
||||
if (isLoading || !hasMorePosts) return;
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
<title>{{meta_title}}</title>
|
||||
<link rel="stylesheet" href="{{asset "built/screen.css"}}">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700&family=Playfair+Display:wght@700&display=swap" rel="stylesheet">
|
||||
<meta name="ghost-api-key" content="YOUR_GHOST_CONTENT_API_KEY"> <!-- IMPORTANT: Replace with your actual Ghost Content API Key -->
|
||||
<meta name="ghost-api-url" content="{{@site.url}}">
|
||||
{{ghost_head}}
|
||||
</head>
|
||||
<body class="{{body_class}} font-sans antialiased">
|
||||
@@ -30,6 +28,7 @@
|
||||
</div>
|
||||
|
||||
{{ghost_foot}}
|
||||
<script src="{{asset "js/ghost-config.js"}}"></script>
|
||||
<script src="{{asset "js/main.js"}}"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user