Open ccchan234 opened 1 year ago
as a note writing software, we cannot always REPLACE the old ones, the old ones have things that i add-ed. i will only UPDATE the old ones.
thanks
hi, i knew some programming. i used gpt4 to help me write backbone for VBA and made several mindmanager macros.
i just asked chatgpt (=gpt3.5) if i can update a .json by a .md (if the contents are same).
it made an example for me, but it should not work, because i forget to tell it that the .json is indeep a block in another .md and not a .json (which i wrongly told it at first).
i think i could help using chatgpt or gpt4 to help writing a plugin or method/function for this. but i'll certainly need the author's help --- i learned basic/logo/pascal/C/VB/python's introduction courses but never really made useful applications, and is complete 0 to javascript.
let me know if the author could help. thanks.
from my experience writing mindmanager's macro (which use winwrap, a clone of VBA), gpt4 didn't know winwrap =/=VBA, also it used some mindmanager API method that didn't exist. The flow of data, however, is very correct and usable (the backbone i mean) these are places where human input is needed. thanks
i am complete 0 in JS and obsidian plugin programming.
may be i'll try it later, thx
finally: asked it to ignore [[ or [ or ] or ]]
me: could you made it to ignore any [[ or [ or ] or ]] when syncing?
gpt:
Sure, you can modify the plugin to ignore any occurences of [[
, ]]
, [
, or ]
when syncing the content between the two files. Here's an updated version of the plugin that does that:
const fs = require('fs');
const yaml = require('js-yaml');
function updateFiles(file1Path, file1aPath, updateFile1a = true) {
let file1Content, file1FrontMatter, file1aData, file1aContent, file1aFrontMatter, file1aJson;
if (updateFile1a) {
// Read the contents of file1a
file1aContent = fs.readFileSync(file1aPath, 'utf-8');
// Extract the YAML front matter and the JSON block from file1a
const file1aFrontMatterEnd = file1aContent.indexOf('---', 4);
file1aFrontMatter = file1aContent.substring(4, file1aFrontMatterEnd);
file1aData = yaml.load(file1aFrontMatter);
const file1aJsonStart = file1aContent.indexOf('```json\n');
const file1aJsonEnd = file1aContent.indexOf('```', file1aJsonStart + 1);
file1aJson = JSON.parse(file1aContent.substring(file1aJsonStart + 8, file1aJsonEnd));
// Read the contents of file1
file1Content = fs.readFileSync(file1Path, 'utf-8');
// Extract the YAML front matter from file1
const file1FrontMatterEnd = file1Content.indexOf('---', 4);
file1FrontMatter = file1Content.substring(4, file1FrontMatterEnd);
// Update the data in file1aData and file1aJson with the data from file1
file1aData.title = yaml.load(file1FrontMatter).title;
file1aData.description = yaml.load(file1FrontMatter).description;
file1aJson.content = file1Content.substring(file1FrontMatterEnd + 4).replace(/\[\[|\]\]|\[|\]/g, '');
// Convert the updated YAML front matter and JSON data back to strings
const updatedFrontMatter = `---\n${yaml.dump(file1aData)}---\n`;
const updatedJson = '```json\n' + JSON.stringify(file1aJson, null, 2) + '\n```';
// Update the contents of file1a with the updated YAML front matter and JSON data
const updatedFile1aContent = updatedFrontMatter + updatedJson;
// Write the updated contents back to file1a
fs.writeFileSync(file1aPath, updatedFile1aContent);
} else {
// Read the contents of file1
file1Content = fs.readFileSync(file1Path, 'utf-8');
// Extract the YAML front matter from file1
const file1FrontMatterEnd = file1Content.indexOf('---', 4);
file1FrontMatter = file1Content.substring(4, file1FrontMatterEnd);
file1aData = yaml.load(file1FrontMatter);
// Read the contents of file1a
file1aContent = fs.readFileSync(file1aPath, 'utf-8');
// Extract the YAML front matter and the JSON block from file1a
const file1aFrontMatterEnd = file1aContent.indexOf('---', 4);
file1aFrontMatter = file1aContent.substring(4, file1aFrontMatterEnd);
const file1aData = yaml.load(file1aFrontMatter);
const file1aJsonStart = file1aContent.indexOf('```json\n');
const file1aJsonEnd = file1aContent.indexOf('```', file1aJsonStart + 1);
file1aJson = JSON.parse(file1aContent.substring(file1aJsonStart + 8, file1aJsonEnd));
// Update the data in file1aData and file1aJson with the data from file1a
file1aData.title = file1aJson.title;
file1aData.description = file1aJson.description;
// Update the contents of file1 with the updated YAML front matter and main content
const updatedFile1Content = `---\n${yaml.dump(file1aData)}---\n${file1aJson.content.replace(/\[\[|\]\]|\[|\]/g, '')}`;
// Write the updated contents back to file1
fs.writeFileSync(file1Path, updatedFile1Content);
}
}
module.exports = {
updateFiles
};
In this updated version, we added a regular expression to the replace()
method on the main content of both files to remove any occurrences of [[
, ]]
, [
, or ]
. This will make sure that those characters are ignored when syncing the content between the two files.
With this updated plugin, you can call the updateFiles()
function with the paths to file1.md
and file1a.md
as before, and pass in a third argument to specify which file to update. The updated plugin will ignore any occurrences of [[
, ]]
, [
, or ]
in the main content of both files.
how it work
me: can you shortly explain how this works? i want to introduce this to my friend, thx
gpt: Certainly! This plugin is designed to update the content of two Markdown files (file1.md
and file1a.md
) with each other's data. In other words, it takes the YAML front matter (metadata) and the main content from one file and adds it to the other file.
Here's a brief overview of how the plugin works:
The plugin reads the contents of file1a.md
and extracts the YAML front matter and JSON block (which contains the main content) using regular expressions.
The plugin then reads the contents of file1.md
and extracts the YAML front matter using a regular expression.
The plugin updates the metadata in the YAML front matter of file1a.md
with the metadata from file1.md
. It also updates the main content in the JSON block of file1a.md
with the main content from file1.md
.
The updated YAML front matter and JSON block are converted back to strings and written to file1a.md
.
If the updateFile1a
parameter is set to false
, the plugin updates file1.md
with the data from file1a.md
in a similar way.
The updated version of the plugin that ignores [[
, ]]
, [
, or ]
characters will simply remove those characters from the main content of both files before updating them.
I hope this helps! Let me know if you have any further questions.
plan:
plan:
- i am trying to test the plugin running outside of obsidian, run as node.js
- if by manually it can update .md or .md/w json, then may be ask gpt to modify it so that it will detect whether the current opened .md is the .md or the .md/w json, and then let us choose the direction of the update.
- the author could help to debug thanks
From basic to rich mode , you can use
when you in basic mode , ctrl + p , click change basic mode to rich mode
command , then it wll create a rich mode md in your vault.
your method is only used once for initialize.
suppose i got basic-123 and then use your ctrl-p to make into rich-123, yes this is working.
but then if i edited the rich-123 into rich-123,456.
and the basic got edited into basic-123,789.
re-perform your function only gives me rich-123, 189
i lost the data "456"<--- this is because sometimes only basic work, sometimes only rich work, so i am forced to modify basic and rich into "different" contents. but i want to merge them together , NOT replace 1 another.
thanks
for "sometimes basic work, sometimes rich work", i mean:
i can compare basic by text comparer like beyond compare, i cant directly compare the json block directly.
the rich can import the .xmind file, basic cant.
sometime some bilinks some hyperlinks only work in 1 and not the other. thats the disadvantage having TWO mode.
would be nice if they can be synced into 1 consistent data. thx
i installed node.js, i think i could end-up have a .js that ask for 2 files, (basic.md and rich.md) and then ask which way to update.
gpt only works on the backbone, i'll need time troubleshooting it.
hi, i just aim to write a .js that could update/merge two rich .md
gpt wrote a backbone, can read 2 files, grab the 2 json block (by braces, in other ways always wrong for me).
but how to compare the 2 json structure is problem. gpt cant give me a successful result.
thanks
hi,
.xmind -> rich worked very well, but rich is too far from plain text markdown, this json block cause troubles.
rich ---copy as markdown----paste---> basic, indeed if i open a comparer like beyond compare 4, the old basic on Lt side, the new copied on Rt side, i can easily see what is new in "new", and click to insert into the existing one. BC4 allow skipping minor things like [[]] used in the old basic map.
so, rich --- update --> basic is possible, MANUALLY.
but now one CANNOT have data flow from basic -> rich. somehow this should be done.
rich <--xxxx- update xxxx----basic
ps: i am already personally keeping both formats, just add -basic/-rich at the end, disk space is cheap nowadays.
let's see how we can let data flow from basic -> rich.
thanks