Skip to content

Commit

Permalink
fix: properly replace wikilinks (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickreynolds authored Jan 11, 2024
1 parent 71ced88 commit 33fa525
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions scripts/upload-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const agent = createAgent({
'createVerifiableCredential',
'dataStoreSaveVerifiableCredential',
'dataStoreORMGetVerifiableCredentials',
'dataStoreORMGetVerifiableCredentialsByClaims',
'packDIDCommMessage',
'unpackDIDCommMessage',
'sendDIDCommMessage',
Expand Down Expand Up @@ -62,15 +63,12 @@ files.forEach((file) => {
const fileContent = fs.readFileSync(file, 'utf8');
const lines = fileContent.split('\n');
lines.forEach((line) => {
const match = line.match(/\[.*\]\((.*)\)/);
const match = line.match(/\[\[.*?\]\]/);
if (match) {
const link = match[1];
if (link.startsWith('http')) {
return;
}
const link = match[0];
links.push({
from: file,
to: path.join(docsPath, link),
to: link,
});
}
});
Expand All @@ -83,9 +81,10 @@ const updatedFiles = files.map((file) => {
links.forEach((link) => {
if (link.from === file) {
const normalizedLink = link.to.replace('docs/', '')
const replacement = normalizedLink.replace('[[', '',).replace(']]', '')
fileContent = fileContent.replace(
`](./${normalizedLink})`,
`](${process.env.AUTHOR_DID}/${normalizedLink.replace('.md', '')})`
normalizedLink,
`[${replacement}](${process.env.AUTHOR_DID}/${encodeURIComponent(replacement)})`
);
}
});
Expand All @@ -106,6 +105,20 @@ const createPost = async (did, post, title) => {
post
}

const getPrevious = await agent.dataStoreORMGetVerifiableCredentialsByClaims({
where: [{ column: 'type', value: ['title'] }],
where: [{ column: 'value', value: [title]}],
order: [{ column: 'issuanceDate', direction: 'DESC' }],
take: 1
})

if (getPrevious.length > 0) {
if (getPrevious[0].verifiableCredential.credentialSubject.post === post) {
return
}
}

console.log("create new revision for post: ", title)
const credential = await agent.createVerifiableCredential({
save: true,
proofFormat: 'jwt',
Expand All @@ -128,12 +141,10 @@ const createPost = async (did, post, title) => {

}


// create post for each file
for (const file of updatedFiles) {
const hash = await createPost(process.env.AUTHOR_DID, file.content, file.title)
// file['hash'] = hash
}

console.log(`\n\nDone creating posts`)

console.log(`\n\nDone creating posts`)

0 comments on commit 33fa525

Please sign in to comment.