Hashnode Sync Plugin


Name

Hashnode Sync

Information

Description

Plugin to sync any interested blog from hashnode to amplenote


Icon

sync


Instructions

Open the Command window using CMD + O (Mac) or Ctrl + O (Windows).

Type Hashnode Sync: Sync Posts and press Enter.

Enter your Hashnode blog address.

Specify the number of blog posts you want to fetch.

Click OK.

The posts will be fetched and sorted by the latest first.


Setting

Hashnode API Key

API Key used for pushing data to hashnode (TBD)


Entry: https://github.com/bhavanichandra/amplenote-hashnode-plugin/build/compiled.js


linkLimitations:

Images may not display correctly, as they rely on URLs hosted by Hashnode.

The plugin only fetches new posts; if a post has already been fetched, it will be skipped.


linkChangelog:

v1.0.0 – Initial release

Fetches latest posts from Hashnode

Skips already fetched posts

Basic post sync functionality implemented

Image URLs remain Hashnode-hosted (display limitations)



linkCode Block

// Javascript updated 06/06/2025, 22:50:24 by Amplenote Plugin Builder from source code within "https://github.com/bhavanichandra/amplenote-hashnode-plugin/build/compiled.js"
(() => {
var __defProp = Object.defineProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
 
// lib/hashnode.js
var hashnode_exports = {};
__export(hashnode_exports, {
getAllPosts: () => getAllPosts
});
var HASHNODE_GRAPHQL_URL = "https://gql.hashnode.com";
var getHashnodePosts = async (host, count) => {
try {
const query = `query Publication($host: String!, $count: Int!) {
publication(host: $host) {
title
posts(first: $count) {
edges {
node {
id
title
brief
url
slug
series {
name
slug
}
content {
markdown
}
}
}
totalDocuments
}
}
}`;
const params = {
host,
count
};
const response = await fetch(HASHNODE_GRAPHQL_URL, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
query,
variables: params
})
});
const responseJson = await response.json();
console.dir(responseJson);
return responseJson;
} catch (error) {
console.error(error);
return {};
}
};
var getAllPosts = async (host, count) => {
const publicationsResponse = await getHashnodePosts(host, count);
if (!publicationsResponse.data) {
return {
message: `No publications found for the host ${host}`,
success: false
};
}
const posts = publicationsResponse.data.publication.posts.edges.map((edge) => {
return {
id: edge.node.id,
title: edge.node.title,
slug: edge.node.slug,
series: edge.node.series,
brief: edge.node.brief,
url: edge.node.url,
content: edge.node.content.markdown
};
});
return {
success: true,
data: {
title: publicationsResponse.data.publication.title,
posts,
totalDocuments: publicationsResponse.data.publication.posts.totalDocuments
}
};
};
 
// lib/plugin.js
var plugin = {
constants: {
fetchCount: 10,
apiKeyConst: "",
hashnodeConstants: {
apiKey: "",
mainTag: "hashnode"
}
},
hashnodeModule: void 0,
appOption: {
"Sync Posts": {
run: async function(app) {
this._initialize(app);
await this._syncAllPosts(app);
}
}
},
_initialize(app, hashnodeModule) {
this.hashnodeModule = hashnodeModule || hashnode_exports;
if (app?.settings["Hashnode API Key"]) {
this.constants.hashnodeConstants.apiKey = app.settings["Hashnode API Key"];
}
},
async _syncAllPosts(app) {
console.log("Started posts sync");
const result = await app.prompt("Hashnode Sync Options", {
inputs: [
{ label: "Hashnode Blog Address or url", type: "string" },
{
label: "No of blogs to retrieve",
type: "string",
value: this.constants.fetchCount
}
]
});
if (!result) {
app.alert("Sync cancelled!");
return;
}
const [hashnodeBlogAddress, postFetchCount] = result;
const publications = await this.hashnodeModule.getAllPosts(
hashnodeBlogAddress,
parseInt(postFetchCount)
);
if (!publications.success) {
app.alert(
`Failed to fetch posts from hashnode. Response: ${publications.message}`
);
return;
}
const publication = publications.data;
const posts = publication.posts;
for (const post of posts) {
const noteData = {
title: post.title,
content: post.content,
tags: [this.constants.hashnodeConstants.mainTag, publication.title]
};
const existingNote = await app.findNote({
name: post.title,
tag: noteData.tags
});
if (existingNote) {
console.debug("Post already synced, skipping", post.title);
continue;
}
const createdNote = await app.notes.create(noteData.title, noteData.tags);
await app.insertNoteContent({ uuid: createdNote.uuid }, noteData.content);
console.debug(`Post: ${post.title} is synced`);
}
console.debug("Post sync done!");
}
};
var plugin_default = plugin;
return plugin;
})()