未验证 提交 8745e398 编写于 作者: frostime's avatar frostime 提交者: GitHub

Merge pull request #48 from frostime/dev

Dev v1.0.4 优化内部代码
module.exports = {
root: true,
env: {node: true, browser: true, es6: true},
parser: "@typescript-eslint/parser",
plugins: [
"@typescript-eslint",
],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:svelte/recommended",
"turbo",
"prettier",
],
parser: "@typescript-eslint/parser",
overrides: [
{
files: ["*.svelte"],
parser: "svelte-eslint-parser",
// Parse the script in `.svelte` as TypeScript by adding the following configuration.
parserOptions: {
parser: "@typescript-eslint/parser",
},
},
],
plugins: ["@typescript-eslint", "prettier"],
rules: {
semi: [2, "always"],
quotes: [2, "double", {"avoidEscape": true}],
"no-async-promise-executor": "off",
"no-prototype-builtins": "off",
"no-useless-escape": "off",
"no-irregular-whitespace": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
// Note: you must disable the base rule as it can report incorrect errors
semi: "off",
quotes: "off",
"no-undef": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-this-alias": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-explicit-any": "off",
"turbo/no-undeclared-env-vars": "off",
"prettier/prettier": "error",
},
};
}
\ No newline at end of file
......@@ -59,4 +59,4 @@ jobs:
artifactErrorsFailBuild: true
artifacts: 'package.zip'
token: ${{ secrets.GITHUB_TOKEN }}
prerelease: true
prerelease: false
node_modules/
tmp/
dist/*
dev/*
deploy.bat
deploy.ps1
.vscode
pnpm-lock.yaml
package.zip
index.css
index.js
......
## [2023-05-21] v1.0.4
现在打开笔记可以自动
## [2023-05-18] v1.0.3
修复一些 bug
......
......@@ -30,6 +30,7 @@
- 启动插件时,自动创建/打开今天的笔记,实现类似 logseq 中的效果
- 如果你不需要,可以在设置面板中关闭这一功能
- 在笔记本设置页面中设置的自定义路径以及模板都依然有效
#### 1.1 我有多个笔记本,哪个笔记本会被用来默认创建笔记呢?
......@@ -57,6 +58,7 @@
- 笔记本名称前面带有 **「√」 符号** ,表示该笔记本下**已经创建了今天的日记**
- 「√」标识会自动更新
- 下拉框会忽略「思源笔记用户指南」笔记本
- 在笔记本设置页面中设置的自定义路径以及模板都依然有效
> - **注意:不要理解错了**,这个下拉框不是用来选择默认的笔记本的,而是用来快速打开日记的!
> - 你完全可以把这个功能理解为把思源自带的「创建日记」的菜单移到最顶层,并添加了日记状态的显示。
......
......@@ -24,6 +24,7 @@
- When you start the plugin, it automatically creates/opens today's daily note, achieving a similar effect as in logseq
- If you don't need it, you can turn off this feature in the settings panel
- The custom paths and templates set in the notebook settings page are still valid
#### 1.1 I have multiple notebooks, which notebook will be used to create notes by default?
......@@ -47,6 +48,7 @@
- Click on a notebook to open/create today's note.
- If there is a "√" flag before a notebook option, it means that diary has already been created for that notebook.
- Ignore "SiYuan User Guide" notebook by default.
- The custom paths and templates set in the notebook settings page are still valid
> - **Note: Don't misunderstand**, this drop-down box is not for selecting the default notebook, but for opening the diary quickly!
> - You can totally interpret this as moving the "Create Diary" menu that comes with Siyuan to the top level and adding a diary status display.
......
{
"name": "siyuan-dailynote-today",
"version": "1.0.1",
"version": "1.0.4",
"description": "",
"main": ".src/index.js",
"scripts": {
"lint": "eslint . --fix --cache",
"dev": "webpack --mode development",
"build": "webpack --mode production"
},
"keywords": [],
"author": "frostime",
"license": "MIT",
"type": "module",
"scripts": {
"make-link": "node ./scripts/make_dev_link.js",
"dev": "vite build --watch",
"build": "vite build",
"git prune": "git remote prune origin"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^6.7.1",
"esbuild-loader": "^3.0.1",
"eslint": "^8.39.0",
"mini-css-extract-plugin": "2.3.0",
"replace-in-file-webpack-plugin": "^1.0.6",
"@sveltejs/vite-plugin-svelte": "^2.0.3",
"@tsconfig/svelte": "^4.0.1",
"@types/node": "^20.2.0",
"fast-glob": "^3.2.12",
"glob": "^7.2.3",
"minimist": "^1.2.8",
"rollup-plugin-livereload": "^2.0.5",
"sass": "^1.62.1",
"sass-loader": "^12.6.0",
"siyuan": "latest",
"svelte": "^3.58.0",
"svelte-loader": "^3.1.7",
"svelte-preprocess": "^5.0.3",
"tslib": "2.4.0",
"typescript": "4.7.4",
"webpack": "^5.76.0",
"webpack-cli": "^5.0.2",
"webpack-sources": "^3.2.3",
"zip-webpack-plugin": "^4.0.1"
"siyuan": "^0.7.1",
"svelte": "^3.57.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.4",
"vite": "^4.3.7",
"vite-plugin-static-copy": "^0.15.0",
"vite-plugin-zip-pack": "^1.0.5"
}
}
}
\ No newline at end of file
......@@ -6,7 +6,7 @@
"en_US": "Daily Note Today"
},
"url": "https://github.com/frostime/siyuan-dailynote-today",
"version": "1.0.3",
"version": "1.0.4",
"description": {
"zh_CN": "1. 启动思源笔记之后,自动开启今天的笔记\n2. 工具栏提供下拉框,快速查看今天的笔记并打开\n3. atrl+右键选择块,可以将块移动到别的笔记文档下",
"en_US": "1. After starting siyuan-note, automatically open today's notes\n2. The toolbar provides a drop-down box to quickly view today's notes and open them\n3. atrl+right click to select the block, you can move the block to daily note under another notebook"
......
此差异已折叠。
import fs from 'fs';
//************************************ Write you dir here ************************************
//Please write the "workspace/data/plugins" directory here
//请在这里填写你的 "workspace/data/plugins" 目录
const targetDir = 'H:\\临时文件夹\\SiYuanDevSpace\\data\\plugins';
//Like this
// const targetDir = `H:\\SiYuanDevSpace\\data\\plugins`;
//********************************************************************************************
//Check
if (!fs.existsSync(targetDir)) {
console.log(`Failed! plugin directory not exists: "${targetDir}"`);
console.log(`Please set the plugin directory in scripts/make_dev_link.js`);
process.exit(1);
}
//check if plugin.json exists
if (!fs.existsSync('./plugin.json')) {
console.error('Failed! plugin.json not found');
process.exit(1);
}
//load plugin.json
const plugin = JSON.parse(fs.readFileSync('./plugin.json', 'utf8'));
const name = plugin?.name;
if (!name || name === '') {
console.log('Failed! Please set plugin name in plugin.json');
process.exit(1);
}
//dev directory
const devDir = `./dev`;
//mkdir if not exists
if (!fs.existsSync(devDir)) {
fs.mkdirSync(devDir);
}
const targetPath = `${targetDir}/${name}`;
//如果已经存在,就退出
if (fs.existsSync(targetPath)) {
console.log('Failed! Target directory already exists');
process.exit(1);
}
//创建软链接
fs.symlinkSync(`${process.cwd()}/dev`, targetPath, 'junction');
console.log(`Done! Created symlink ${targetPath}`);
......@@ -55,6 +55,7 @@
type="button"
content={contents.update}
settingKey="Update"
settingValue={""}
on:click={onClick}
/>
</div>
......@@ -82,7 +82,7 @@ export class ToolbarMenuItem {
/**
* 初始化的时候,加载所有的笔记本
*/
autoOpenDailyNote() {
async autoOpenDailyNote() {
info('自动开启日记');
if (notebooks.notebooks.length > 0) {
if (settings.settings.OpenOnStart === true) {
......
......@@ -198,21 +198,23 @@ export async function createDiary(notebook: Notebook, todayDiaryHpath: string) {
* @param notebook_index 笔记本的 index
*/
export async function openDiary(notebook: Notebook) {
let todayDiaryPath = notebook.dailynotePath;
info(`打开日记 ${notebook.name}${todayDiaryPath}`);
//queryNotebooks() 保证了 todayDiaryPath 不为 null
let docs = await getDocsByHpath(todayDiaryPath!, notebook);
if (docs != null && docs.length > 0) {
let doc = docs[0];
let id = doc.id;
window.open(`siyuan://blocks/${id}`);
notify(`${i18n.Open}${notebook.name}`, 'info', 2500);
} else {
let id = await createDiary(notebook, todayDiaryPath!);
window.open(`siyuan://blocks/${id}`);
notify(`${i18n.Create}: ${notebook.name}`, 'info', 2500);
}
// let todayDiaryPath = notebook.dailynotePath;
// info(`打开日记 ${notebook.name}${todayDiaryPath}`);
// let docs = await getDocsByHpath(todayDiaryPath!, notebook);
await serverApi.createDailyNote(notebook.id, "");
notify(`${i18n.Open}: ${notebook.name}`, 'info', 2000);
// if (docs != null && docs.length > 0) {
// let doc = docs[0];
// let id = doc.id;
// window.open(`siyuan://blocks/${id}`);
// notify(`${i18n.Open}: ${notebook.name}`, 'info', 2500);
// } else {
// let id = await createDiary(notebook, todayDiaryPath!);
// window.open(`siyuan://blocks/${id}`);
// notify(`${i18n.Create}: ${notebook.name}`, 'info', 2500);
// }
}
export function compareVersion(v1Str: string, v2Str: string) {
......
......@@ -22,7 +22,7 @@ class SettingManager {
settings: any = {
OpenOnStart: true as boolean, //启动的时候自动打开日记
DiaryUpToDate: false as boolean, //自动更新日记的日期
NotebookSort: 'custom-sort' as NotebookSorting, //笔记本排序方式
NotebookSort: 'doc-tree' as NotebookSorting, //笔记本排序方式
DefaultNotebook: '', //默认笔记本的 ID
IconPosition: 'left' as IconPosition //图标放置位置
};
......@@ -43,7 +43,7 @@ class SettingManager {
}
set(key: any, value: any) {
info(`Setting update: ${key} = ${value}`)
// info(`Setting update: ${key} = ${value}`)
if (!(key in this.settings)) {
error(`"${key}" is not a setting`);
return;
......
......@@ -34,7 +34,7 @@
},
"DiaryUpToDate": {
"title": "Auto refresh diary's path as day passed",
"text": "When new day comes, the plugin will automatically update the dairy's path, take effect after reloading"
"text": "When new day comes, the plugin will automatically update the status"
}
},
"Open": "Open daily note",
......
......@@ -8,7 +8,7 @@
},
"DefaultNotebook": {
"title": "设置默认笔记本 ID",
"text": "设置默认的笔记本 ID留空时表示选择排位第一的笔记本",
"text": "设置默认的笔记本 ID, 留空时表示选择排位第一的笔记本",
"placeholder": "请复制笔记本 ID"
},
"update": {
......@@ -34,7 +34,7 @@
},
"DiaryUpToDate": {
"title": "自动随日期更新",
"text": "进入新的一天时, 自动更新日记的路径到新的日期, 重启后生效"
"text": "进入新的一天时, 自动提醒并更新日记状态"
}
},
"Open": "打开日记",
......
/**
* Copyright (c) 2023 frostime. All rights reserved.
*/
import { isMobile, openTab, Plugin } from 'siyuan';
import { openTab, Plugin } from 'siyuan';
import Setting from './components/setting.svelte'
import { ToolbarMenuItem } from './components/toolbar-menu';
import { notify, compareVersion } from './func';
import { info, setI18n, i18n } from './utils';
import { info, setI18n } from './utils';
import { settings } from './global-setting';
import notebooks from './global-notebooks';
import { ContextMenu } from './components/move-menu';
......@@ -15,6 +15,7 @@ import * as serverApi from './serverApi';
export default class DailyNoteTodayPlugin extends Plugin {
app: any;
toolbar_item: ToolbarMenuItem;
component_setting: Setting;
......@@ -49,14 +50,15 @@ export default class DailyNoteTodayPlugin extends Plugin {
this.initToolbarItem();
this.initUpToDate();
eventBus.subscribe('UpdateAll', () => {this.updateAll()});
// 如果有笔记本,且设置中允许启动时打开,则打开第一个笔记本
this.toolbar_item.autoOpenDailyNote();
await this.toolbar_item.autoOpenDailyNote();
// 等日记创建,完成了状态更新后再读取新的状态
setTimeout(
() => this.toolbar_item.updateDailyNoteStatus(), 2000
() => this.toolbar_item.updateDailyNoteStatus(), 1000
);
eventBus.subscribe('UpdateAll', () => {this.updateAll()});
let end = performance.now();
info(`启动耗时: ${end - start} ms`);
......
......@@ -10,39 +10,6 @@ async function request(url: string, data: any) {
return res;
}
function parseBody(body: any) {
return body;
}
async function test() {
let notebooks = await lsNotebooks();
console.log(notebooks);
let notebookId = notebooks?.notebooks[0].id;
try {
let notebookConf = await getNotebookConf('20220305173526-4yjl33h');
console.log(notebookConf);
} catch (err) {
console.log(err);
}
try {
let block = await getBlockByID('20220316145830-u0u6srg');
console.log(block);
} catch (err) {
console.log(err);
}
try {
let block = await renderSprig('/daily note/{{now | date "2006/01"}}/{{now | date "2006-01-02"}}');
console.log(block);
} catch (err) {
console.log(err);
}
// try {
// await moveBlock('20230512192002-q5ekmhh', '20230512192017-eyc4dyb', null);
// } catch (err) {
// console.log(err);
// }
}
export async function sql(sql: string) {
let sqldata = {
......@@ -67,6 +34,11 @@ export async function createDocWithMd(notebookId: string, path: string, markdown
return request(url, data);
}
export async function createDailyNote(notebookId: string, app: string) {
let url = '/api/filetree/createDailyNote';
return request(url, { notebook: notebookId, app: app });
}
export async function getNotebookConf(notebookId: string) {
let data = { notebook: notebookId };
let url = '/api/notebook/getNotebookConf';
......
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"
export default {
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
// for more information about preprocessors
preprocess: vitePreprocess(),
}
\ No newline at end of file
{
"compilerOptions": {
"noImplicitAny": true,
"module": "commonjs",
"target": "es6"
},
"include": [
"src/**/*.ts"
],
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": [
"ES2020",
"DOM",
"DOM.Iterable"
],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "Node",
// "allowImportingTsExtensions": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
/* Linting */
"strict": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
/* Svelte */
/**
* Typecheck JS in `.svelte` and `.js` files by default.
* Disable checkJs if you'd like to use dynamic types in JS.
* Note that setting allowJs false does not prevent the use
* of JS in `.svelte` files.
*/
"allowJs": true,
"checkJs": true,
"types": [
"node",
"vite/client",
"svelte"
]
},
"include": [
"tools/**/*.ts",
"src/**/*.ts",
"src/**/*.d.ts",
"src/**/*.tsx",
"src/**/*.vue"
],
"references": [
{
"path": "./tsconfig.node.json"
}
],
"root": "."
}
\ No newline at end of file
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true
},
"include": [
"vite.config.ts"
]
}
\ No newline at end of file
import { resolve } from "path"
import { defineConfig, loadEnv } from "vite"
import minimist from "minimist"
import { viteStaticCopy } from "vite-plugin-static-copy"
import livereload from "rollup-plugin-livereload"
import { svelte } from "@sveltejs/vite-plugin-svelte"
import zipPack from "vite-plugin-zip-pack";
import fg from 'fast-glob';
const args = minimist(process.argv.slice(2))
const isWatch = args.watch || args.w || false
const devDistDir = "./dev"
const distDir = isWatch ? devDistDir : "./dist"
console.log("isWatch=>", isWatch)
console.log("distDir=>", distDir)
export default defineConfig({
plugins: [
svelte(),
viteStaticCopy({
targets: [
{
src: "./README*.md",
dest: "./",
},
{
src: "./icon.png",
dest: "./",
},
{
src: "./preview.png",
dest: "./",
},
{
src: "./plugin.json",
dest: "./",
},
{
src: "./src/i18n/**",
dest: "./i18n/",
},
],
}),
],
// https://github.com/vitejs/vite/issues/1930
// https://vitejs.dev/guide/env-and-mode.html#env-files
// https://github.com/vitejs/vite/discussions/3058#discussioncomment-2115319
// 在这里自定义变量
define: {
"process.env.DEV_MODE": `"${isWatch}"`,
},
build: {
// 输出路径
outDir: distDir,
emptyOutDir: false,
// 构建后是否生成 source map 文件
sourcemap: false,
// 设置为 false 可以禁用最小化混淆
// 或是用来指定是应用哪种混淆器
// boolean | 'terser' | 'esbuild'
// 不压缩,用于调试
minify: !isWatch,
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(__dirname, "src/index.ts"),
// the proper extensions will be added
fileName: "index",
formats: ["cjs"],
},
rollupOptions: {
plugins: [
...(
isWatch ? [
livereload(devDistDir),
{
//监听静态资源文件
name: 'watch-external',
async buildStart() {
const files = await fg([
'src/i18n/*.json',
'./README*.md',
'./plugin.json'
]);
for (let file of files) {
this.addWatchFile(file);
}
}
}
] : [
zipPack({
inDir: './dist',
outDir: './',
outFileName: 'package.zip'
})
]
)
],
// make sure to externalize deps that shouldn't be bundled
// into your library
external: ["siyuan", "process"],
output: {
entryFileNames: "[name].js",
assetFileNames: (assetInfo) => {
if (assetInfo.name === "style.css") {
return "index.css"
}
return assetInfo.name
},
},
},
}
})
\ No newline at end of file
const path = require("path");
const fs = require("fs");
const webpack = require("webpack");
const {EsbuildPlugin} = require("esbuild-loader");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const ZipPlugin = require("zip-webpack-plugin");
const sveltePreprocess = require("svelte-preprocess");
const ReplaceInFileWebpackPlugin = require('replace-in-file-webpack-plugin');
module.exports = (env, argv) => {
const isPro = argv.mode === "production";
const plugins = [
new MiniCssExtractPlugin({
filename: isPro ? "dist/index.css" : "index.css",
})
];
let entry = {
"index": "./src/index.ts",
};
if (isPro) {
entry = {
"dist/index": "./src/index.ts",
};
// plugins.push(new webpack.BannerPlugin({
// banner: () => {
// return fs.readFileSync("LICENSE").toString();
// },
// }));
plugins.push(new CopyPlugin({
patterns: [
{from: "preview.png", to: "./dist/"},
{from: "icon.png", to: "./dist/"},
{from: "README*.md", to: "./dist/"},
{from: "plugin.json", to: "./dist/"},
{from: "src/i18n/", to: "./dist/i18n/"},
],
}));
//把图片地址全部替换成国内的托管
// plugins.push(new ReplaceInFileWebpackPlugin([
// {
// dir: 'dist',
// files: ['README.md'],
// rules: [{
// search: /\.?\/?asset/g,
// replace: 'https://gitcode.net/frostime/siyuan-plugin-daily-note/-/raw/main/asset'
// }]
// }
// ]));
plugins.push(new ZipPlugin({
filename: "package.zip",
algorithm: "gzip",
include: [/dist/],
pathMapper: (assetPath) => {
return assetPath.replace("dist/", "");
},
}));
} else {
plugins.push(new CopyPlugin({
patterns: [
{from: "src/i18n/", to: "./i18n/"},
],
}));
}
return {
mode: argv.mode || "development",
watch: !isPro,
devtool: isPro ? false : "eval",
output: {
filename: "[name].js",
path: path.resolve(__dirname),
libraryTarget: "commonjs2",
library: {
type: "commonjs2",
},
},
externals: {
siyuan: "siyuan",
},
entry,
optimization: {
minimize: true,
minimizer: [
new EsbuildPlugin(),
],
},
resolve: {
alias: {
svelte: path.resolve('node_modules', 'svelte')
},
extensions: [".ts", ".scss", ".svelte"],
mainFields: ['svelte', 'browser', 'module', 'main'],
conditionNames: ['svelte']
},
module: {
rules: [
{
test: /\.ts(x?)$/,
include: [path.resolve(__dirname, "src")],
use: [
{
loader: "esbuild-loader",
options: {
target: "es6",
}
},
],
},
{
test: /\.svelte$/,
// include: [path.resolve(__dirname, "src")],
use: [
{
loader: 'svelte-loader',
options: {
preprocess: sveltePreprocess({
alias: [['ts', 'typescript']],
typescript: {
tsconfigFile: "./tsconfig.json",
}
})
}
}
]
},
{
// required to prevent errors from Svelte on Webpack 5+, omit on Webpack 4
test: /node_modules\/svelte\/.*\.mjs$/,
resolve: {
fullySpecified: false
}
},
{
test: /\.scss$/,
include: [path.resolve(__dirname, "src")],
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader", // translates CSS into CommonJS
},
{
loader: "sass-loader", // compiles Sass to CSS
},
],
}
],
},
plugins,
};
};
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册