Skip to content

Conversation

@JakeSCahill
Copy link
Contributor

@JakeSCahill JakeSCahill commented Jan 6, 2025

  • Added: archive-attachments extension to automate the archiving of grouped attachments based on configurable file patterns.
  • Enhanced: replace-attributes-in-attachments extension by allowing customizable file patterns and user-defined replacement rules.
  • Breaking change: The replace-attributes-in-attachments extension now requires configuration to specify which attachments should have their text replaced. Previously, the extension worked on all YAML attachments by default, which was inefficient as not all attachments required replacements.

Motivation

In redpanda-data/docs#937, we introduce a new quickstart that requires users to download multiple files as attachments. To make the UX as streamlined as possible, we want to allow users to download and extract the files in a single archive. Allowing writers to define a group of attachments to use to build an archive reduces manual effort and ensures consistent packaging of related resources.

Benefits

  • Efficiency: Automatically creates compressed archives, saving time and minimizing errors.
  • Flexibility: Configurable file patterns and replacement rules allow precise control over which attachments are archived and how their content is modified.
  • Organization: Prevents archive overwriting using unique naming conventions, ensuring multiple archives coexist.

Configuration Example

antora:
  extensions:
    - require: '../docs-extensions-and-macros/extensions/archive-attachments.js'
      data:
        archives:
           - component: 'ROOT'
              output_archive: 'redpanda-quickstart.tar.gz'
              file_patterns:
                - '**/test-resources/**/docker-compose/**'

Tests

https://deploy-preview-90--docs-extensions-and-macros.netlify.app/preview/test/#attachments

Related PRs

Because this is a breaking change and we have an automation that auto-upgrades the package using latest, we need to merge these PRs in before we release this new major version of the extension to avoid auto-upgrading to this major version:

@JakeSCahill JakeSCahill requested a review from Deflaimun January 6, 2025 19:13
@netlify
Copy link

netlify bot commented Jan 6, 2025

Deploy Preview for docs-extensions-and-macros ready!

Name Link
🔨 Latest commit 5f51917
🔍 Latest deploy log https://app.netlify.com/sites/docs-extensions-and-macros/deploys/678129ecbb3a380008b8aeef
😎 Deploy Preview https://deploy-preview-90--docs-extensions-and-macros.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

* @param {string} tempDir - The temporary directory containing files to archive.
* @returns {Promise<Buffer>} - A promise that resolves to the tar.gz buffer.
*/
function createTarInMemory(tempDir) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this have async?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not needed but because it returns a promise, marking it as async makes it more explicit 😄


// Asynchronously create the tar.gz archive in memory
logger.debug(`Starting tar creation for ${compName}@${compVersion}`);
const archiveBuffer = await createTarInMemory(tempDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this try-catch the error generated in the function?

for (const attachment of matched) {
const relPath = attachment.out.path;
// Include only the part of the path after '_attachments/'
const attachmentsSegment = '_attachments/';
Copy link
Contributor

@Deflaimun Deflaimun Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if const, consider creating outside of the for-loop and define at the start of the script

const attachmentsIndex = relPath.indexOf(attachmentsSegment);

if (attachmentsIndex === -1) {
logger.warn(`'_attachments/' segment not found in path: ${relPath}. Skipping this file.`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the variable instead

Copy link
Contributor

@Deflaimun Deflaimun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really good new feature. New quickstart is looking 🔥

@JakeSCahill
Copy link
Contributor Author

Thanks @Deflaimun ! I also implemented the fs.mkdtempSync() function that you mentioned and it works great.

Copy link
Contributor

@Deflaimun Deflaimun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks really good. thanks for implementing the changes

@JakeSCahill JakeSCahill merged commit 6dd1333 into main Jan 10, 2025
5 checks passed
@JakeSCahill JakeSCahill deleted the archiver branch January 10, 2025 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants