Skip to content

Commit

Permalink
Merge pull request #109 from viqueen/issue/site-108-link-card-embeds
Browse files Browse the repository at this point in the history
Issue/site 108 link card embeds
  • Loading branch information
viqueen authored Oct 7, 2024
2 parents d23f379 + 58a4c45 commit 8ebe624
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 96 deletions.
1 change: 1 addition & 0 deletions modules/apis/confluence/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ interface ResourceDefinition {
url: string;
generator: { icon: { url: string } };
name: string;
summary?: string;
'@type': string;
}

Expand Down
18 changes: 15 additions & 3 deletions modules/cli/commands/extract/extract-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,30 @@ export const extractObjects = async (content: Content, output: Output) => {
resourceUrl: item.attrs?.url
};
});
if (inlineCards.length < 1) return;
const blockCards = filter(
content.body,
(node) => node.type === 'blockCard'
).map((item) => {
return {
resourceUrl: item.attrs?.url
};
});

const cards = [...inlineCards, ...blockCards];

if (cards.length < 1) return;

const resolvedObjects = await confluence.getObjects(inlineCards);
const resolvedObjects = await confluence.getObjects(cards);
resolvedObjects.forEach((item) => {
if (!item.body) {
return;
}
const data = item.body.data;
const { url, name, generator } = data;
const { url, name, generator, summary } = data;
const definition = {
name,
generator,
summary,
url: rewriteUrl(url),
'@type': data['@type']
};
Expand Down
5 changes: 3 additions & 2 deletions modules/cli/commands/extract/helpers/adf-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const identityProcessor = (node: ADFEntity) => {
return node;
};

const inlineCardProcessor = (node: ADFEntity) => {
const cardProcessor = (node: ADFEntity) => {
const url = rewriteUrl(node.attrs?.url);
return {
type: node.type,
Expand All @@ -48,14 +48,15 @@ const mediaSingleProcessor = (node: ADFEntity) => {
const scrubContent = (doc: any) => {
return scrubAdf(doc, {
nodeReplacements: {
blockCard: cardProcessor,
bulletList: identityProcessor,
codeBlock: identityProcessor,
date: identityProcessor,
emoji: identityProcessor,
expand: identityProcessor,
extension: identityProcessor,
heading: identityProcessor,
inlineCard: inlineCardProcessor,
inlineCard: cardProcessor,
inlineExtension: identityProcessor,
media: identityProcessor,
mediaSingle: mediaSingleProcessor,
Expand Down
150 changes: 65 additions & 85 deletions modules/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ import { Command } from 'commander';
import { confluence } from './clients';
import { webpackBuild } from './commands/build/webpack.build';
import { defaultSiteProperties } from './commands/build/webpack.config';
import {
extractBlogs,
extractSpace,
generateAttachmentsThumbnails
} from './commands/extract';
import { extractBlogs, extractSpace } from './commands/extract';
import { extractContent } from './commands/extract/extract-content';
import { extractPageTree } from './commands/extract/extract-page-tree';
import { extractSiteEmojis } from './commands/extract/extract-site-emojis';
Expand All @@ -36,95 +32,79 @@ import { initChangelog, initOutput } from './conf';

const program = new Command();

program
.command(`extract <spaceKey>`)
.description(`extract all content and media from a confluence space`)
.option('--force', 'enforce extracting content assets', false)
.option('--dest <dest>', 'with output destination', 'output')
.option(
'--changelog <changelog>',
'with changelog destination',
'changelog'
)
.action(async (spaceKey: string, options) => {
const outputDestination = path.resolve(process.cwd(), options.dest);
const changelogDestination = path.resolve(
process.cwd(),
options.changelog
const withOptions = (cmd: string, description: string) => {
return program
.command(cmd)
.description(description)
.option('--force', 'enforce extracting content assets', false)
.option('--dest <dest>', 'with output destination', 'output')
.option(
'--changelog <changelog>',
'with changelog destination',
'changelog'
);
const output = initOutput({ spaceKey, destination: outputDestination });
const changelog = initChangelog({
spaceKey,
destination: changelogDestination
});
await extractSpace(spaceKey, output, changelog, { ...options });
await extractSiteEmojis(output, options);
});
};

program
.command('extract-blogs <spaceKey>')
.description('extract all blogs from a confluence space')
.option('--dest <dest>', 'with output destination', 'output')
.option('--changelog <log>', 'with changelog destination', 'changelog')
.action(async (spaceKey: string, options) => {
const outputDestination = path.resolve(process.cwd(), options.dest);
const changelogDestination = path.resolve(process.cwd(), options.log);
const output = initOutput({ spaceKey, destination: outputDestination });
const changelog = initChangelog({
spaceKey,
destination: changelogDestination
});
await extractBlogs(spaceKey, output, changelog);
withOptions(
`extract <spaceKey>`,
`extract all content and media from a confluence space`
).action(async (spaceKey: string, options) => {
const outputDestination = path.resolve(process.cwd(), options.dest);
const changelogDestination = path.resolve(process.cwd(), options.changelog);
const output = initOutput({ spaceKey, destination: outputDestination });
const changelog = initChangelog({
spaceKey,
destination: changelogDestination
});
await extractSpace(spaceKey, output, changelog, { ...options });
await extractSiteEmojis(output, options);
});

program
.command('generate-thumbnails <spaceKey>')
.description('generate attachment thumbnails for a confluence space')
.option('--force', 'enforce generating thumbnails', false)
.option('--dest <dest>', 'with output destination', 'output')
.action(async (spaceKey: string, options) => {
const outputDestination = path.resolve(process.cwd(), options.dest);
const output = initOutput({ spaceKey, destination: outputDestination });
await generateAttachmentsThumbnails(output, options);
withOptions(
'extract-blogs <spaceKey>',
'extract all blogs from a confluence space'
).action(async (spaceKey: string, options) => {
const outputDestination = path.resolve(process.cwd(), options.dest);
const changelogDestination = path.resolve(process.cwd(), options.changelog);
const output = initOutput({ spaceKey, destination: outputDestination });
const changelog = initChangelog({
spaceKey,
destination: changelogDestination
});
await extractBlogs(spaceKey, output, changelog);
});

program
.command('extract-content <spaceKey> <contentId>')
.description('extract specific content from a confluence space')
.option('--force', 'enforce extracting content assets', false)
.option('--dest <dest>', 'with output destination', 'output')
.option('--changelog <log>', 'with changelog destination', 'changelog')
.action(async (spaceKey: string, id: string, options) => {
const outputDestination = path.resolve(process.cwd(), options.dest);
const changelogDestination = path.resolve(process.cwd(), options.log);
const output = initOutput({ spaceKey, destination: outputDestination });
const changelog = initChangelog({
spaceKey,
destination: changelogDestination
});
const content = await confluence.getContentById({ id }, false);
await extractContent(content, output, changelog, options);
withOptions(
'extract-content <spaceKey> <contentId>',
'extract specific content from a confluence space'
).action(async (spaceKey: string, id: string, options) => {
const outputDestination = path.resolve(process.cwd(), options.dest);
const changelogDestination = path.resolve(process.cwd(), options.changelog);
const output = initOutput({ spaceKey, destination: outputDestination });
const changelog = initChangelog({
spaceKey,
destination: changelogDestination
});
const content = await confluence.getContentById({ id }, false);
await extractContent(content, output, changelog, options);
});

program
.command('extract-page-tree <spaceKey> <contentId>')
.description('extract specific page tree from a confluence space')
.option('--force', 'enforce extracting content assets', false)
.option('--dest <dest>', 'with output destination', 'output')
.option('--changelog <log>', 'with changelog destination', 'changelog')
.action(async (spaceKey: string, id: string, options) => {
const outputDestination = path.resolve(process.cwd(), options.dest);
const changelogDestination = path.resolve(process.cwd(), options.log);
const output = initOutput({ spaceKey, destination: outputDestination });
const changelog = initChangelog({
spaceKey,
destination: changelogDestination
});
await extractPageTree({ id, title: '' }, output, changelog, {
...options,
asHomepage: true
}).catch((error) => console.error(error.response.data));
withOptions(
'extract-page-tree <spaceKey> <contentId>',
'extract specific page tree from a confluence space'
).action(async (spaceKey: string, id: string, options) => {
const outputDestination = path.resolve(process.cwd(), options.dest);
const changelogDestination = path.resolve(process.cwd(), options.changelog);
const output = initOutput({ spaceKey, destination: outputDestination });
const changelog = initChangelog({
spaceKey,
destination: changelogDestination
});
await extractPageTree({ id, title: '' }, output, changelog, {
...options,
asHomepage: true
}).catch((error) => console.error(error.response.data));
});

program
.command('extract-emojis <spaceKey>')
Expand Down
2 changes: 1 addition & 1 deletion modules/site/content/content-ancestors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type ContentAncestorsProps = {
export const ContentAncestors = ({ content }: ContentAncestorsProps) => {
if (content.type === 'blogpost' || content.asHomepage) return <></>;
return (
<div style={{ margin: 40 }}>
<div style={{ margin: 20 }}>
<Breadcrumbs>
{content.parentPages?.map((item: Identifier, index: number) => {
const href =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

.blog-post-item a {
font-size: 18px;
color: #0052cc;
display: block;
margin-bottom: 10px;
text-decoration: none;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const BlogPostItemCover = ({ content }: { content: Content }) => {
return (
<img
alt={`its-a-cover-up`}
src={content.coverUrl}
src={`${content.coverUrl}&h=300`}
className="blog-post-item-cover"
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
}

.home-page-child-item a {
color: #0052cc;
display: block;
text-decoration: none;
font-size: 16px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export const RegularPageChildrenMacro = ({
href={`/notes/${titleToPath(child.title)}/`}
style={{
textDecoration: 'none',
color: '#0052CC',
fontSize: 16
}}
>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@labset/confluence-static-site",
"version": "2.2.1",
"version": "2.3.0",
"description": "confluence static site",
"bin": {
"confsite": "./dist/cli/index.js"
Expand Down

0 comments on commit 8ebe624

Please sign in to comment.