Compare commits

..

No commits in common. "main" and "@matthiesenxyz/astro-hashnode@0.1.1" have entirely different histories.

28 changed files with 326 additions and 786 deletions

View File

@ -1,8 +1,8 @@
name: "Changesets: Build Changesets for Dependabot"
on: pull_request
#on:
#workflow_dispatch:
#on: pull_request
on:
workflow_dispatch:
permissions:
contents: write

View File

@ -1,6 +1,5 @@
name: "Changesets: Publish Packages from main"
on:
workflow_dispatch:
push:
branches:
- main

View File

@ -14,4 +14,4 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: kevinzunigacuellar/coauthor-action@v0.1.2
- uses: kevinzunigacuellar/coauthor-action@v0.1.1

View File

@ -1,11 +1,9 @@
name: "Sync to GitLab"
name: "Sync: GitHub => GitLab"
on:
- push
- delete
permissions: read-all
jobs:
sync:
runs-on: ubuntu-latest
@ -14,7 +12,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: MatthiesenXYZ/git-sync-action@v1.1
- uses: jauderho/git-repo-sync@63782025e80e84c48b25a1ee6bb9a22a3bd570d3
with:
# Such as https://github.com/wangchucheng/git-repo-sync.git
target-url: ${{ secrets.GITLAB_URL }}

View File

@ -31,6 +31,4 @@ You can now edit files in `package`. Please note that making changes to those fi
[MIT Licensed](./LICENSE). Made with ❤️ by [Adam M.](https://github.com/adammatthiesen).
This project is cloned to [Gitea](https://git.matthiesen.dev)
This project is also cloned to [GitLab](https://gitlab.com/matthiesenxyz/astro-hashnode)

View File

@ -13,7 +13,7 @@
"ci:publish": "pnpm changeset publish"
},
"devDependencies": {
"@biomejs/biome": "1.6.1",
"@biomejs/biome": "1.6.0",
"@changesets/cli": "^2.27.1"
}
}

View File

@ -1,54 +1,5 @@
# @matthiesenxyz/astro-hashnode
## 0.1.8
### Patch Changes
- 6ccd6dc: Bump dependencies:
- @tailwindcss/vite from to
- astro-font from to
- tailwindcss from to
- @astrojs/node from to
- astro from to
## 0.1.7
### Patch Changes
- 6464de2: [fix] add extra fallback option for ogImage
## 0.1.6
### Patch Changes
- cf327f2: Update README.md
- e54bfbb: [Internal] better handling of the `hashnodeURL` input to verify that including `http` or `https` in the URL does not break the entire integration
## 0.1.5
### Patch Changes
- 784cb63: view transition updates
## 0.1.4
### Patch Changes
- 337a5b0: added new keyword "cms" and updated Dependencies
## 0.1.3
### Patch Changes
- fc94343: This updates internal `AIK` as well as impliments ViewTransitions with a disable switch in the user config
## 0.1.2
### Patch Changes
- 7733762: Add SSR support for blog posts (Tags are still prerendered)
## 0.1.1
### Patch Changes

View File

@ -11,7 +11,7 @@ pnpm astro add @matthiesenxyz/astro-hashnode
```
```bash
npx astro add @matthiesenxyz/astro-hashnode
npm astro add @matthiesenxyz/astro-hashnode
```
```bash
@ -54,7 +54,6 @@ export default defineConfig({
astroHashnode({
hashnodeURL: 'astroplayground.hashnode.dev', // Your hashnode URL
landingPage: true, // Lets you disable the default landing page!
useViewTransitions: true, // Lets you enable/disable the default included ViewTransitions.
layoutComponent: './src/layouts/YourLayout.astro' // Lets you change the default Layout.astro being used by the Integration Pages.
verbose: false // Change to Verbose console output
})

View File

@ -1,6 +1,6 @@
{
"name": "@matthiesenxyz/astro-hashnode",
"version": "0.1.8",
"version": "0.1.1",
"description": "An Integration to bring your Hashnode Headless Blog content into Astro!",
"author": {
"email": "adam@matthiesen.xyz",
@ -12,7 +12,6 @@
"astro-integration",
"withastro",
"astro",
"cms",
"hashnode",
"blog",
"graphql",
@ -44,15 +43,15 @@
"vite": "^5.1.5"
},
"dependencies": {
"@tailwindcss/vite": "4.0.0-alpha.9",
"astro-font": "^0.0.78",
"astro-integration-kit": "0.6.0",
"@tailwindcss/vite": "4.0.0-alpha.7",
"astro-font": "^0.0.77",
"astro-integration-kit": "^0.5.1",
"astro-remote": "^0.3.2",
"astro-seo": "^0.8.3",
"graphql": "^16.8.1",
"graphql-request": "^6.1.0",
"picocolors": "^1.0.0",
"tailwindcss": "4.0.0-alpha.9",
"tailwindcss": "4.0.0-alpha.7",
"ultrahtml": "^1.5.3"
}
}

View File

@ -15,7 +15,6 @@ export default defineIntegration({
optionsSchema,
plugins: [ ...corePlugins, addDtsPlugin ],
setup({ options }) {
type outputType = "static" | "hybrid" | "server";
return {
"astro:config:setup": ({
@ -51,13 +50,6 @@ export default defineIntegration({
throw new AstroError(message)
}
// Check if output is static or hybrid
const checkIfStatic = (output: outputType) => {
if (output === "static") { return true }
if (output === "hybrid") { return true }
return false
}
hashLogNoVerbose("Setting up Astro-Hashnode Integration")
// Check for Hashnode URL
@ -69,7 +61,8 @@ export default defineIntegration({
hashLog("Setting up Virtual Imports and Layout Component")
// Setup Layout Component
let layoutComponentPath: string;
// biome-ignore lint/suspicious/noImplicitAnyLet: This is a false positive
let layoutComponentPath
if (options.layoutComponent) {
layoutComponentPath = rootResolve(options.layoutComponent)
@ -88,8 +81,8 @@ export default defineIntegration({
content: readFileSync(resolve("./definitions/astro-hashnode.d.ts"), "utf-8"),
})
// Add & Setup Tailwind CSS
hashLog("Setting up 'Tailwind CSS v4' Integration")
// Add & Setup Tailwind CSS
const twplugin = tailwindcss();
for (const twp of twplugin) {
addVitePlugin(twp);
@ -109,19 +102,22 @@ export default defineIntegration({
}
})
// Add Page Routes
hashLog("Setting up Page Routes")
// Add Page Routes
if (options.landingPage) {
injectRoute({
pattern: config.base,
entrypoint: resolve("./pages/index.astro"),
prerender: true,
});
}
injectRoute({
pattern: `${config.base}blog`,
entrypoint: resolve("./pages/blog/index.astro"),
})
injectRoute({
pattern: `${config.base}blog/[slug]`,
entrypoint: resolve("./pages/blog/[slug].astro"),
})
injectRoute({
pattern: `${config.base}blog/about`,
entrypoint: resolve("./pages/blog/about.astro"),
@ -129,26 +125,7 @@ export default defineIntegration({
injectRoute({
pattern: `${config.base}blog/tags/[tag]`,
entrypoint: resolve("./pages/blog/tags/[tag].astro"),
prerender: true,
})
// Add Blog Post Routes based on output type
if ( checkIfStatic(config.output) ) {
// Static & Hybrid Routes
injectRoute({
pattern: `${config.base}blog/[slug]`,
entrypoint: resolve("./pages/blog/[slug].astro"),
prerender: true,
})
} else {
// Server Routes
injectRoute({
pattern: `${config.base}blog/[slug]`,
entrypoint: resolve("./pages/ssr-pages/[slug].astro"),
})
}
},
"astro:config:done": ({ logger }) => {
const HashLogger = logger.fork(c.bold(c.blue("Astro-Hashnode")));

View File

@ -20,24 +20,16 @@ const { post } = Astro.props;
height={50}
class="rounded-3xl mr-3"
loading="eager"
transition:animate={"fade"}
transition:name={'author:' + post.author.profilePicture}
/>
<div class="mt-3 flex">
<span transition:animate={"fade"}
transition:name={'author:' + post.author.name}
>{post.author.name}</span>
<span>{post.author.name}</span>
<span class="mx-3 block font-bold text-slate-500">.</span>
</div>
</div>
</div>
<div class="mb-5 flex w-full flex-row items-center justify-center md:mb-0 md:w-auto md:justify-start">
<span transition:animate={"fade"}
transition:name={'hero:' + post.publishedAt}
>{getFormattedDate(post.publishedAt)}</span>
<span>{getFormattedDate(post.publishedAt)}</span>
<span class="mx-3 block font-bold text-slate-500">.</span>
<span transition:animate={"fade"}
transition:name={'hero:' + post.readTimeInMinutes}
>{post.readTimeInMinutes} min read</span>
<span>{post.readTimeInMinutes} min read</span>
</div>
</div>

View File

@ -7,27 +7,6 @@ const aboutPageData = await getAboutPage();
const baseURL = import.meta.env.BASE_URL;
const pathname = new URL(Astro.request.url).pathname;
// remove leading and trailing slash
const removeTrailingAndLeadingSlash = (str:string) => {
// define checked string as the original string
let checkedStr = str;
// remove leading slash
if (str.startsWith("/")) {
checkedStr = str.slice(1);
}
// remove trailing slash
if (str.endsWith("/")) {
checkedStr = str.slice(0, -1);
}
// return checked string
return checkedStr;
}
const currentPath = removeTrailingAndLeadingSlash(pathname);
---
<header class="flex bg-blue-200 w-full p-3">
<h1 class="text-2xl">
@ -56,22 +35,8 @@ const currentPath = removeTrailingAndLeadingSlash(pathname);
</a>
</h1>
<div class="ml-5 pt-0.5 text-lg">
<a
class=`mr-3 ${currentPath === "" ? "font-bold" : ""}`
href={baseURL}
>Home
</a>
<a
class=`mr-3 ${currentPath === "blog" ? "font-bold" : ""}`
href={`${baseURL}blog`}
>Blog
</a>
{ aboutPageData && (
<a
class=`mr-3 ${currentPath === "blog/about" ? "font-bold" : ""}`
href={`${baseURL}blog/about`}
>About
</a>
) }
<a class="mr-3" href={baseURL}>Home</a>
<a class="mr-3" href={`${baseURL}blog`}>Blog</a>
{aboutPageData && <a href={`${baseURL}blog/about/`}>About</a>}
</div>
</header>

View File

@ -26,7 +26,6 @@ const p = await getPost(post.slug);
src={p.coverImage.url}
alt={post.title}
inferSize={true}
transition:name={'hero:' + p.coverImage.url}
/>
<div class="flex flex-col m-4">
<p class="mb-2 text-lg">{post.brief}</p>

View File

@ -1,6 +1,6 @@
declare module 'virtual:astro-hashnode/config' {
const Config: import("./src/schemas/user-config").Options;
export default config as Config;
const userConfig: import("./src/schemas/user-config").Options;
export default config as userConfig;
}
declare module 'virtual:astro-hashnode/components' {

View File

@ -1,28 +1,18 @@
import { gql, GraphQLClient } from "graphql-request";
import type { AllPostsData, PostOrPageData, PublicationData } from "./schema";
import config from "virtual:astro-hashnode/config";
import Config from "virtual:astro-hashnode/config";
export const getClient = () => {
return new GraphQLClient("https://gql.hashnode.com")
}
export function removeHTTPSProtocol(url: string) {
return url.replace(/^https?:\/\//, '');
}
export function removeHTTPProtocol(url: string) {
const fixHTTPS = removeHTTPSProtocol(url);
return fixHTTPS.replace(/^http?:\/\//, '');
}
const newURL = removeHTTPProtocol(config.hashnodeURL);
export const getAllPosts = async () => {
const client = getClient();
const allPosts = await client.request<AllPostsData>(
gql`
query allPosts {
publication(host: "${newURL}") {
publication(host: "${Config.hashnodeURL}") {
title
posts(first: 20) {
pageInfo{
@ -66,7 +56,7 @@ export const getPost = async (slug: string) => {
const data = await client.request<PostOrPageData>(
gql`
query postDetails($slug: String!) {
publication(host: "${newURL}") {
publication(host: "${Config.hashnodeURL}") {
post(slug: $slug) {
author{
name
@ -102,7 +92,7 @@ export const getAboutPage = async () => {
const page = await client.request<PostOrPageData>(
gql`
query pageData {
publication(host: "${newURL}") {
publication(host: "${Config.hashnodeURL}") {
staticPage(slug: "about") {
title
content {
@ -124,14 +114,11 @@ export const getPublication = async () => {
const data = await client.request<PublicationData>(
gql`
query pubData {
publication(host: "${newURL}") {
publication(host: "${Config.hashnodeURL}") {
title
displayTitle
descriptionSEO
favicon
author {
profilePicture
}
preferences {
logo
disableFooterBranding

View File

@ -60,9 +60,6 @@ export const PublicationDataSchema = z.object({
displayTitle: z.string(),
descriptionSEO: z.string(),
favicon: z.string(),
author: z.object({
profilePicture: z.string(),
}),
preferences: z.object({
logo: z.string(),
disableFooterBranding: z.boolean(),

View File

@ -1,3 +1,3 @@
import astroHashnode from "./astro-hashnode";
import astroHashnode from "./astro-hashnode.js";
export default astroHashnode;

View File

@ -6,10 +6,6 @@ import { getPublication } from '../hn-gql'
import { SEO } from "astro-seo";
import { AstroFont } from "astro-font";
import type { AstroHashnodeLayoutProps } from '../proptypes/layouttypes'
import { ViewTransitions } from 'astro:transitions';
import config from "virtual:astro-hashnode/config";
const useTranstions = config.useViewTransitions;
const pubData = await getPublication();
@ -41,7 +37,7 @@ const { pageTitle, hideFooter, hideHeader, ogImage } = Astro.props as AstroHashn
basic: {
title: pageTitle ? pageTitle + " | " + pubHeader : pubHeader,
type: 'text',
image: ogImage || pubData.favicon || pubData.author.profilePicture,
image: ogImage || pubData.favicon,
},
optional: {
description: pubData.descriptionSEO,
@ -58,11 +54,10 @@ const { pageTitle, hideFooter, hideHeader, ogImage } = Astro.props as AstroHashn
]
}}
/>
{useTranstions && <ViewTransitions />}
</head>
<body>
<div class="flex flex-col">
{!hideHeader && <Header transition:animate="none" />}
{!hideHeader && <Header />}
<div class="flex flex-wrap flex-col mt-0 mr-auto mb-0 ml-auto lg:w-[60%]">
<slot />
</div>

View File

@ -18,7 +18,6 @@ export async function getStaticPaths() {
}
const { slug } = Astro.params;
const post = await getPost(slug);
---
<Layout pageTitle={post.title} ogImage={post.coverImage.url}>
<article class="bg-white p-3 mt-3 flex flex-col">
@ -28,9 +27,8 @@ const post = await getPost(slug);
alt={post.title}
inferSize={true}
loading="eager"
transition:name={'hero:' + post.coverImage.url}
/>
<h1 class="text-4xl font-bold pt-5" transition:name={'banner'} transition:animate={'fade'}>{post.title}</h1>
<h1 class="text-4xl font-bold pt-5">{post.title}</h1>
<h2 class="text-xl pt-3 pb-3" aria-label="CoverPhoto Subtitle">{post.subtitle}</h2>
<Author post={post} />

View File

@ -9,9 +9,7 @@ const data = await getAboutPage();
<Layout pageTitle="About">
<div class="flex flex-col justify-center p-2">
<h2 class="text-3xl mb-3"
transition:name={'banner'}
transition:animate={'fade'}>{data.title}</h2>
<h2 class="text-3xl mb-3">{data.title} Page</h2>
<div class="about-content">
<Markdown content={data.content.markdown}
components={{

View File

@ -10,7 +10,7 @@ const allPosts = data.publication.posts.edges;
---
<Layout pageTitle="Blog">
<div class="flex flex-col justify-center items-center p-2">
<h2 transition:animate={'fade'} transition:name={'banner'} class="text-2xl pt-2 font-semibold">{`Welcome to ${pub.displayTitle || pub.title}`}</h2>
<h2 class="text-2xl pt-2 font-semibold">{`Welcome to ${pub.displayTitle || pub.title}`}</h2>
<Posts allPosts={allPosts}/>
</div>

View File

@ -4,13 +4,10 @@ import Posts from '../../../components/Posts.astro';
import {getAllPosts} from '../../../hn-gql';
import Taged from '../../../components/Tag.astro';
export const prerender = true
export async function getStaticPaths() {
const data = await getAllPosts();
const allPosts = data.publication.posts.edges;
// biome-ignore lint/complexity/useFlatMap: <explanation>
const allTags = [...new Set(allPosts.map((post) => post.node.tags).flat())];
const jsonObject = allTags.map((object) => JSON.stringify(object));
const uniqueSet = new Set(jsonObject);
@ -18,10 +15,8 @@ export async function getStaticPaths() {
return uniqueTags.map((uTag) => {
const filteredPosts: { node: { author: { name: string; profilePicture: string; }; publishedAt: string; title: string; subtitle: string; brief: string; slug: string; readTimeInMinutes: number; content: { html: string; }; tags: { name: string; slug: string; }[]; coverImage: { url: string; }; }; }[] = [];
// biome-ignore lint/complexity/noForEach: <explanation>
allPosts.forEach((post) => {
const tags = post.node.tags;
// biome-ignore lint/complexity/noForEach: <explanation>
tags.forEach((tag) => {
if(tag.slug === uTag.slug) {
filteredPosts.push(post)

View File

@ -13,14 +13,8 @@ import background from "../assets/blog.jpg";
height={1080}
width={1920}
loading="eager"
transition:name={'background:' + background}
transition:animate={'fade'}
/>
<div
class="absolute p-2 flex flex-col justify-center items-center z-10 bg-purple-50 lg:w-2/5 h-1/4 rounded-md"
transition:name={'banner'}
transition:animate={'fade'}
>
<div class="absolute p-2 flex flex-col justify-center items-center z-10 bg-purple-50 lg:w-2/5 h-1/4 rounded-md">
<div class="flex pb-5 mb-5 text-5xl text-purple-800">
<p>Hashnode Blog</p>
</div>

View File

@ -1,58 +0,0 @@
---
import { Layout } from "virtual:astro-hashnode/components";
import { getPost } from '../../hn-gql';
import Tag from '../../components/Tag.astro';
import Author from '../../components/Author.astro';
import { Markup } from 'astro-remote';
import { Image } from 'astro:assets';
import RemoteImage from '../../components/astro-remote/RemoteImage.astro';
const { slug } = Astro.params;
const checkSlug = (slug:string|undefined) => {
if (slug !== undefined) {
return slug as string;
}
return " " as string;
}
const post = await getPost(checkSlug(slug));
---
{post ? (
<Layout pageTitle={post.title} ogImage={post.coverImage.url}>
<article class="bg-white p-3 mt-3 flex flex-col">
<Image
class="rounded-lg"
src={post.coverImage.url}
alt={post.title}
inferSize={true}
loading="eager"
transition:name={'hero:' + post.coverImage.url}
/>
<h1 class="text-4xl font-bold pt-5">{post.title}</h1>
<h2 class="text-xl pt-3 pb-3" aria-label="CoverPhoto Subtitle">{post.subtitle}</h2>
<Author post={post} />
<div class="flex flex-wrap justify-center items-center mt-5 mb-5">
{post.tags && post.tags.map((tag) => <Tag tag={tag} />)}
</div>
<div class="post-details">
<Markup
content={post.content.html}
components={{
img: RemoteImage
}}
/>
</div>
</article>
</Layout>) : (
<Layout pageTitle="404">
<div class="text-center my-20">
<h1 class="text-4xl font-bold">404</h1>
<p>Post not found</p>
</div>
</Layout>
)}

View File

@ -1,4 +1,7 @@
import { z } from "astro/zod";
import { createResolver } from 'astro-integration-kit';
const { resolve } = createResolver(import.meta.url)
export function LayoutConfigSchema() {
return z
@ -6,29 +9,9 @@ export function LayoutConfigSchema() {
.optional()
}
export const optionsSchema = z.object({
/**
* The URL of the Hashnode blog
*/
hashnodeURL: z.string(),
/**
* Allows the user to disable the default landing page and use their own Astro site instead of a landing page.
* @default true
*/
landingPage: z.boolean().default(true),
/**
* Allows the user to enable/disable the Astro ViewTransitions component.
* @default true
* @see https://docs.astro.build/en/guides/view-transitions/ for more information about ViewTransitions
*/
useViewTransitions: z.boolean().default(true),
/**
* Allows the user to change the layout component used for Astro-Hashnode pages.
*/
layoutComponent: LayoutConfigSchema(),
/**
* Allows the user to enable verbose logging
* @default false
*/
verbose: z.boolean().default(false),
});

View File

@ -1,18 +1,12 @@
import { defineConfig } from "astro/config";
import astroHashnode from "@matthiesenxyz/astro-hashnode";
// import node from '@astrojs/node';
// https://astro.build/config
export default defineConfig({
// output: 'server',
// adapter: node({
// mode: 'standalone',
// }),
integrations: [
astroHashnode({
hashnodeURL: "astroplayground.hashnode.dev",
verbose: true,
disableViewTransitions: false,
})
],
});

View File

@ -11,13 +11,12 @@
"astro": "astro"
},
"dependencies": {
"@astrojs/node": "8.2.4",
"@matthiesenxyz/astro-hashnode": "workspace:*",
"astro": "^4.5.6"
"astro": "^4.4.15",
"@matthiesenxyz/astro-hashnode": "workspace:*"
},
"devDependencies": {
"@astrojs/check": "^0.5.9",
"@types/node": "^20.11.28",
"typescript": "^5.4.2"
"@astrojs/check": "^0.5.7",
"@types/node": "^20.11.25",
"typescript": "^5.3.3"
}
}

File diff suppressed because it is too large Load Diff