generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
11,586 additions
and
463 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const fs = require("fs"); | ||
const convert = require("xml-js"); | ||
|
||
function readFiles(dirname, onFileContent, onError, done) { | ||
fs.readdir(dirname, function (err, filenames) { | ||
if (err) { | ||
onError(err); | ||
return; | ||
} | ||
|
||
for (let filename of filenames) { | ||
if (!filename.endsWith(".csl")) continue; | ||
const content = fs.readFileSync(dirname + filename); | ||
onFileContent(filename, convert.xml2js(content.toString())); | ||
} | ||
|
||
done(); | ||
}); | ||
} | ||
|
||
const cslList = []; | ||
|
||
readFiles( | ||
"../styles/", | ||
function (filename, content) { | ||
if (content && content.elements) { | ||
const style = content.elements.find((el) => el.name === "style"); | ||
|
||
if (style) { | ||
const info = style.elements.find((el) => el.name === "info"); | ||
|
||
if (info) { | ||
const styleLink = info.elements.find( | ||
(el) => | ||
el.name === "link" && el.attributes.rel === "self" | ||
); | ||
const titleEl = info.elements.find( | ||
(el) => el.name === "title" | ||
); | ||
const title = titleEl.elements[0].text; | ||
const id = styleLink.attributes.href.split("/").pop(); | ||
|
||
cslList.push({ value: id, label: title }); | ||
} | ||
} | ||
} | ||
}, | ||
function (err) { | ||
throw err; | ||
}, | ||
function () { | ||
fs.writeFileSync( | ||
"./src/csl-list.json", | ||
JSON.stringify(cslList, null, 2) | ||
); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.