Skip to content

Commit

Permalink
add new version
Browse files Browse the repository at this point in the history
  • Loading branch information
metal-young committed Nov 16, 2022
1 parent ff1c7bd commit 6cbc541
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 7 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/releases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Build obsidian plugin

on:
push:
tags:
- "*"

env:
PLUGIN_NAME: obsidian-to-flomo

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: "14.x"
- name: Build
id: build
run: |
npm install
npm run build --if-present
mkdir ${{ env.PLUGIN_NAME }}
cp main.js manifest.json ${{ env.PLUGIN_NAME }}
zip -r ${{ env.PLUGIN_NAME }}.zip ${{ env.PLUGIN_NAME }}
ls
echo "::set-output name=tag_name::$(git tag --sort version:refname | tail -n 1)"
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ github.ref }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: false
- name: Upload zip file
id: upload-zip
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ env.PLUGIN_NAME }}.zip
asset_name: ${{ env.PLUGIN_NAME }}-${{ steps.build.outputs.tag_name }}.zip
asset_content_type: application/zip
- name: Upload main.js
id: upload-main
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./main.js
asset_name: main.js
asset_content_type: text/javascript
- name: Upload manifest.json
id: upload-manifest
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./manifest.json
asset_name: manifest.json
asset_content_type: application/json
- name: Upload styles.css
id: upload-styles
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./styles.css
asset_name: styles.css
asset_content_type: application/json
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.1] - 2022-11-16

### Added

- test button to settings page.

### Changed

- Optimize prompt information.

38 changes: 32 additions & 6 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
import { App, Editor, MarkdownView, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';

interface Settings {
flomoAPI: string;
Expand All @@ -21,8 +21,7 @@ export default class ObsidianToFlomo extends Plugin {
editorCallback: (editor: Editor, view: MarkdownView) => {
this.checkResult = this.checkSettings();
if (this.checkResult) {
new sendFlomeAPI(this.app, this).sendRequest(editor.getSelection());
new Notice('The current content has been sent to Flomo');
new sendFlomeAPI(this.app, this).sendRequest(editor.getSelection(),'The current content has been sent to Flomo');
}
}
});
Expand All @@ -33,8 +32,7 @@ export default class ObsidianToFlomo extends Plugin {
editorCallback: (editor: Editor, view: MarkdownView) => {
this.checkResult = this.checkSettings();
if (this.checkResult) {
new sendFlomeAPI(this.app, this).sendRequest(editor.getSelection());
new Notice('The selection has been sent to Flomo');
new sendFlomeAPI(this.app, this).sendRequest(editor.getSelection(),'The selection has been sent to Flomo');
}
}
});
Expand Down Expand Up @@ -70,13 +68,36 @@ class sendFlomeAPI {
this.plugin = plugin;
}

async sendRequest(text: string){
async sendRequest(text: string, successMsg: string) {
const xhr = new XMLHttpRequest();
xhr.open("POST",this.plugin.settings.flomoAPI);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify({
"content": text
}));
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
console.log(xhr.responseText);
//能不能转化成json格式
try {
const json = JSON.parse(xhr.responseText);
console.log(json);
//json里的code如果是0就返回true,如果不是0就提示失败,如果是-1就返回json里的message
if (json.code == 0) {
new Notice(successMsg);
}
else if (json.code == -1) {
new Notice(json.message + 'please check your settings');
}
else {
new Notice('please check your settings');
}
}
catch (e) {
new Notice('please check your settings');
}
}
}
}
}

Expand Down Expand Up @@ -105,5 +126,10 @@ class SampleSettingTab extends PluginSettingTab {
this.plugin.settings.flomoAPI = value;
await this.plugin.saveSettings();
}));

containerEl.createEl('button', {text: 'Send a test request'}).addEventListener('click', () => {
new sendFlomeAPI(this.app, this.plugin).sendRequest('This is a test request', 'The test request has been sent to Flomo');
}
);
}
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-to-flomo",
"name": "Obsidian to Flomo",
"version": "0.1.0",
"version": "0.1.1",
"minAppVersion": "0.15.0",
"description": "Quickly share content to Flomo.",
"author": "Xiaoyu Li",
Expand Down

0 comments on commit 6cbc541

Please sign in to comment.