Skip to content

Commit

Permalink
Add createPlaybook method
Browse files Browse the repository at this point in the history
  • Loading branch information
marieflorescontact committed Aug 4, 2022
1 parent 53fd100 commit d99dc51
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/asciidoctorWebViewConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export class AsciidoctorWebViewConverter {
const resolvedPath = resolveAntoraImageIds(target, this.contentCatalog, this.src)
if (resolvedPath !== undefined) {
// fixme: update the image_uri on the Node
return `<img src= "${resolvedPath}" alt="">`
}
return this.baseConverter.convert(node, transform)
}
Expand Down
67 changes: 40 additions & 27 deletions src/features/antora/antoraSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,52 +115,65 @@ export async function getAttributes (textDocumentUri: Uri): Promise<{ [key: stri

export async function getContentCatalog (textDocumentUri: Uri, extensionContext: ExtensionContext): Promise<ContentCatalog | undefined> {
try {
const activeAntoraConfig = await getActiveAntoraConfig(textDocumentUri, extensionContext)
if (activeAntoraConfig === undefined) {
return undefined
}
const contentSourceRootPath = path.dirname(activeAntoraConfig.fsPath)
const contentSourceRepositoryRootPath = workspace.getWorkspaceFolder(activeAntoraConfig).uri.fsPath
// https://docs.antora.org/antora/latest/playbook/content-source-start-path/#start-path-key
const startPath = path.relative(contentSourceRepositoryRootPath, contentSourceRootPath)
const playbook = {
content: {
sources: [{
url: contentSourceRepositoryRootPath,
branches: 'HEAD',
startPath,
}],
},
runtime: {},
site: {},
}
try {
const playbook = await createPlaybook(textDocumentUri, extensionContext)
if (playbook !== undefined) {
const contentAggregate = await aggregateContent(playbook)
return classifyContent(playbook, contentAggregate)
} catch (e) {
console.log(`Unable to create contentCatalog : ${e}`)
return undefined
}
return undefined
} catch (e) {
if (e instanceof AntoraDisabledError) {
return undefined
} else {
console.log(`Unable to create contentCatalog : ${e}`)
throw e
}
}
}

async function createPlaybook (textDocumentUri: Uri, extensionContext: ExtensionContext): Promise<{
site: {};
runtime: {};
content: {
sources: {
startPath: string;
branches: string;
url: string
}[]
}
} | undefined> {
const activeAntoraConfig = await getActiveAntoraConfig(textDocumentUri, extensionContext)
if (activeAntoraConfig === undefined) {
return undefined
}
const contentSourceRootPath = path.dirname(activeAntoraConfig.fsPath)
const contentSourceRepositoryRootPath = workspace.getWorkspaceFolder(activeAntoraConfig).uri.fsPath
// https://docs.antora.org/antora/latest/playbook/content-source-start-path/#start-path-key
const startPath = path.relative(contentSourceRepositoryRootPath, contentSourceRootPath)
return {
content: {
sources: [{
url: contentSourceRepositoryRootPath,
branches: 'HEAD',
startPath,
}],
},
runtime: {},
site: {},
}
}

export async function getSrc (textDocumentUri: Uri, contentCatalog: ContentCatalog | undefined) {
const antoraConfig = await getAntoraConfig(textDocumentUri)
const doc = await parseAntoraConfig(textDocumentUri)
const contentSourceRootPath = path.dirname(antoraConfig.fsPath)
if (doc !== {} && contentCatalog !== undefined) {
try {
const file = contentCatalog.getByPath({
component: doc.name,
version: doc.version,
path: path.relative(contentSourceRootPath, textDocumentUri.path),
}
component: doc.name,
version: doc.version,
path: path.relative(contentSourceRootPath, textDocumentUri.path),
}
)
return {
component: file.src.component,
Expand Down

0 comments on commit d99dc51

Please sign in to comment.