I recently read Creating Authentic Human Connections Within A Remote Team posted by Smashing Magazine and I really connected with this article. I have been working as a remote tech writer for three years now and I can say that this experience and what Randy Tolentino wrote is very true. I especially that "Reading emotions across the distance" section was point on. However, I don't agree that using emojis is necessarily a good solution. I think the use of emojis greatly depends on the personality of the person on the other side of the screen. Personally, if I'm having a back and forth with someone on an IM, I just ask if I can video conference with them for 5-10 minutes. That face to face time is much better at connecting to that other person and reinforce that we are humans and not just resources (as Randy mentions in this article).
Tuesday, August 27, 2019
Wednesday, August 14, 2019
Modifying an Exported Space From Confluence
Introduction
During times of Confluence migrations (from one instance to another), you may find yourself in a situation where the new Confluence instance has a space that has the same spacekey as an old space that you are attempting to import. This month's post will show you how to get around that issue.Required skills
Exporting and editing
To start, you will need to expand the exported zip file (that comes from exporting a space). In this expanded directory, you will need to edit the
exportDescriptor.properties file. In this file, modify the spaceKey property to the desired spacekey and save your change.
In
entities.xml, search and replace the following items listed in this table (replacing NEWKEY with an unused and new spacekey you wish to use in the new Confluence instance):| Search for | Replace with |
|---|---|
[CDATA[OLDKEY]
| [CDATA[NEWKEY]
|
OLDKEY
| NEWKEY
|
spaceKey=OLDKEY
| spaceKey=NEWKEY
|
[OLDKEY:
| [NEWKEY:
|
key=OLDKEY]
| key=NEWKEY]
|
<spaceKey>OLDKEY</spaceKey>
| <spaceKey>NEWKEY</spaceKey>
|
ri:space-key="OLDKEY"
| ri:space-key="NEWKEY"
|
ri:space-key=OLDKEY
| ri:space-key=NEWKEY
|
<ac:parameter ac:name="spaces">OLDKEY</ac:parameter>
| <ac:parameter ac:name="spaces">NEWKEY</ac:parameter>
|
<ac:parameter ac:name="spaceKey">OLDKEY</ac:parameter>
| <ac:parameter ac:name="spaceKey">NEWKEY</ac:parameter>
|
<property name="lowerDestinationSpaceKey"><![CDATA[NEWKEY]]></property>
|
<property name="lowerDestinationSpaceKey"><![CDATA[newkey]]></property>
|
<property name="lowerKey">![CDATA[NEWKEY]]></property>
|
<property name="lowerKey"><![CDATA[newkey]]></property>
|
spaceKey=OLDKEY
| spaceKey=NEWKEY
|
spacekey=oldkey
| spacekey=newkey
|
With those two files updated, re-zip all content back together, rename it to the original zip file (you may need to remove the old zip file or just rename it just in case), and upload it to your new Confluence instance as you would normally to import a space.
Additional details can be found here: https://confluence.atlassian.com/confkb/how-to-copy-or-rename-a-space-in-confluence-169578.html
Sunday, July 14, 2019
Generate a Path/File Report of HTML Documents
Introduction
While there a bazillions of ways to generate a text file with all the directories and the respective files (Bash comes to mind), I wanted to explore Shell.js for doing this task so it could be chained together in a bigger set of Node.js tools I've been cobbling together recently. I also wanted to make it simpler than recent scripts I've written by foregoing Commander.js and just have it accept one argument which would be the directory to generate the report from.In theory, I should be able to execute this command and get a text file back with all the files found there and all the nested files and directories:
node app.js <directory>Required skills and npm packages
You should be fairly comfortable with JavaScript and have some exposure to shell.js (0.8.3).
Required modules and variable setup
We'll need to require two modules (shell and fs), grab the user supplied directory (path), and set up a variable to hold the list of items found therein (output).
const shell = require('shelljs');
const fs = require('fs');
const path = process.argv[2];
var output = '';
...Generate the report
If the path is supplied, then we should inform the user that the script in generating the report, recursively gather all the contents of the target directories, and save out the data to a text file called directorySiteMap.txt.
...
if (path) {
console.log('Generating directorySiteMap.txt');
shell.ls('-LR', path).map(function(file) {
output += file + '\n';
});
fs.writeFileSync(directorySiteMap.txt, output);
...
Quit if path isn't supplied
If the path isn't supplied, the script should state as such to the user and gracefully quit.
...
} else {
console.log('Directory argument is required. Quitting.');
process.exit(1);
}
Wrapping up
Now we should save this script as
directorySiteMap.js and execute it using this command: node directorySiteMap.js <directory>Friday, June 14, 2019
Write The Docs 2019
The following is a summary of some of the presentations I attended and enjoyed.
Draw the Docs presented by Alicja Raszkowska was interesting as she advocated for using more graphics (particularly cartoons) in technical documentation. While I enjoy the notion of this, one must know their audience before they can start adding cartoons to illustrate their product and/or points. She is also developing a tool called mermaid that creates visual content similar to Visio but with custom images and markdown input.
Sarah Moir's presentation called "Just Add Data: Make it easier to prioritize your documentation" makes a good case for using analytics and other feedback to sort out prioritization of which documents should get the tech writer's attention.
Matt Reiner gave a very energetic presentation called "Show Me the Money: How to Get Your Docs the Love and Support They Deserve" which outlines how to make a business case for getting more resources for documentation. In Matt's presentation, he provides a good and detailed method for creating a business case and how to pitch it to management. I believe this is a good resource for all tech writers!
"How to edit other people's content without pissing them off" by Ingrid Towey was an interesting presentation on editing other people's content. The four principles are as follows: Assure that the content originator that we are all on the same side, when editing content, it's an edit and not an edict, explain why you're editing their content (preferable before you do it), and get help when thinks don't go smoothly. Good idea if one isn't already applying this.
Kathleen Juell's "Writer? Editor? Teacher?" presentation basically provided parallels to how tech writers can leverage teaching philosophy (particular college level) to technical writing. The topics she covered was basic documentation layout, design, and goals, providing templates, peer editing/reviews, and writing like as a teacher or an editor (clarify, explain, and goals). As a former college teacher myself, I see the lines between a teacher and tech write to be very blurry.
Shannon Crabill provided some thoughts and guidelines for how to manage documentation for an open source project in her talk called "Documenting for Open Source". Some tips include avoid assuming the technical knowledge of your readers (one should include a requirements section in your guides as to not lead on the readers who may get frustrated layer in the document when they discover they cannot complete it), README files are required, how to get users started, provide yourself or your team with templates (to avoid issues like duplicate PRs), and always provide links to any and all resources.
Heather Stenson provided some thoughts on how to get non-writers to contribute to documentation in a presentation called "Any friend of the docs is a friend of mine: Cultivating a community of documentation advocates". She defined who "friends of docs" are (those who write but are not technical writers), the different levels of friends of docs, how to get people to contribute more, strategies to find, support, communicate, and provide feedback to these friends, how to overcome obstacles friends of docs may encounter, and how to continue building this doc-friendly culture.
Chris Bush gave a dry-humor filled presentation called "SDK Reference Manuals: A flow-based approach". Overall it was dry but reassured that the process for creating, maintaining, and updating SDK docs haven't really changed all that much in years.
This conference also live-streamed and posted all their presenters on this YouTube playlist: https://www.youtube.com/playlist?list=PLZAeFn6dfHpmuHCu5qsIkmp9H5jFD-xq-
Tuesday, May 14, 2019
Using Nightmare.js to Generate a Sitemap From Confluence
Introduction
In a recent project, I had a task to generate a list of documents in a particular Confluence space. I chose to explore my options using Nightmare.js. Using this Node.js (version 10.11.0) module, it allowed me to programmatically enter my credentials into Confluence, navigate to a specific document, and gather a list of documents (thanks to the target document using the Children Display macro that listed all the documents of the parent page of the target space). I also wanted this script to take arguments (flags) such as the username, password, spacekey, output file, and a delay value so that the process can be automated for a variety of reasons.Required skills and npm packages
This tutorial requires a number of skills and/or npm modules to complete everything mentioned herein:
- Confluence (5.x): You should be comfortable with creating pages that utilize the Children Display macro
- Nightmare (3.0.1): have some familiarity with the basics of this module
- Commander (2.19.0): have some familiarity with the basics of this module
- Cheerio (1.0.0-rc.2): have some familiarity with the basics of this module
- CSS: basic knowledge of how to select elements
- JavaScript: fair knowledge of how to use JavaScript
Setting up requirements
const Nightmare = require("nightmare");
const cheerio = require('cheerio');
const program = require('commander');
const fs = require('fs');
....Set up nightmare and flag options
The next two lines sets up nightmare to display it's process as it's going through the steps we'll program it to navigate and a selector to find the content we're looking for in our target document. The
confluenceSelector is the CSS selector that will be used to find the desired content in the main body of the Confluence document.....
const nightmare = Nightmare({
show: true
});
const confluenceSelector = '#main-content';
....Note: you don't want to see an Electron window pop up and nightmare to do it's stuff, set
show to false.Next, we set up the flags and their usage using commander's features:
...
program
.version('0.0.1')
.usage('-u <username> -p <password> -s <spacekey> -f <output.txt> -d <milliseconds>')
.option('-u, --user', '*required* Username id')
.option('-p, --password', '*required* User\'s password')
.option('-s, --spacekey', '*required* Spacekey for the Confluence space')
.option('-f --file', 'Text file to be used for tracking Confluence document names. Can be set to either true (defaults to the spacekey naming scheme) or a file name.')
.option('-d, --delay', 'Delay (in milliseconds) to wait for server response')
.parse(process.argv);
...
With the flags set, we now need to parse them into an object that we'll use throughout the rest of the script. We loop through the
program.rawArgs value provided by the commander module. In this loop, we are looking for specific flags so we can associate the flag with the value associated with it....var argument = {};
for (var i = 0; i < program.rawArgs.length; i++) {
if (program.rawArgs[i] == '--user' || program.rawArgs[i] == '-u') {
arguments.user = program.rawArgs[i + 1];
}
if (program.rawArgs[i] == '--password' || program.rawArgs[i] == '-p') {
arguments.pass = program.rawArgs[i + 1];
}
if (program.rawArgs[i] == '--spacekey' || program.rawArgs[i] == '-s') {
arguments.spacekey = program.rawArgs[i + 1];
}
if (program.rawArgs[i] == '--delay' || program.rawArgs[i] == '-d') {
arguments.delay = parseInt(program.rawArgs[i + 1]);
}
if (program.rawArgs[i] == '--file' || program.rawArgs[i] == '-f') {
arguments.file = program.rawArgs[i + 1];
}
}...
Since the delay flag is optional, we should set up a fallback if the user doesn't supply one. In this case, we're setting the delay to 10 seconds though you can adjust this delay value to a number you're comfortable with your Confluence server responding a login page request.
...
if (!arguments.delay) {
arguments.delay = 10000;
console.log('Server response delay not set. Assuming ' + arguments.delay + ' millisecond delay.');
}
...Now we should set up the file path where we keep the site map information. If the user doesn't supply a file to output our data to, the script will use a fallback based on the submitted spacekey name.
...
if (arguments.file) {
if (arguments.file.length > 5) {
var confluenceSiteMap = arguments.file;
} else {
var confluenceSiteMap = arguments.spacekey + '-site_map.txt';
}
} else {
var confluenceSiteMap = confluenceSiteMap.txt;
}...The next thing our script will need is the Confluence URL to the site map document. Using the Children Display macro in your target Confluence space, we can gather all the document links in a single space by scraping this one document. Note: you should set up this Confluence document accordingly before executing this script and ensure it's named Site Map. Otherwise, you'll need to change the values in
arguments.confluence.
...if (arguments.spacekey) {
arguments.confluence = <base Confluence URL> + '/display/' + arguments.spacekey + '/Site+Map';
}...With the arguments parsed, we should check that the user supplied the required flags. If any of these flags weren't submitted, then the script should gracefully exit.
...
if (!arguments.user || !arguments.pass || !arguments.spacekey) {
if (!arguments.user) { // user id is required
console.log('Username is required.');
}
if (!arguments.pass) { // password is required
console.log('Password is required.')
} if (!arguments.spacekey) {
console.log('Spacekey is required.')
}
process.exit(1);
...Pull content with nightmare
With the required flags set, we can now request a document from Confluence using your credentials. This chunk of code starts the nightmare.js process by navigating the Electron browser to the site map page in Confluence. The process belows assumes that a login is required when the target page is loaded, enters user supplied username and password in the appropriate fields (denoted by their element ids), click the login button (denoted by it's element id), wait for a period of time (hopefully long enough for the server to respond), grab the content from the predetermined CSS selector via theevaluate method, return the data for parsing later, and close the Electron browser....
} else {
console.log('Getting document link list from ' + arguments.confluence);
nightmare
.goto(arguments.confluence)
.type('#os_username', arguments.user)
.type('#os_password', arguments.pass)
.click('#loginButton')
.wait(arguments.delay)
.evaluate(confluenceSelector => {
return {
html: document.querySelector(confluenceSelector).innerHTML
}
}, confluenceSelector)
.end()...Parse content with Cheerio
Now that nightmare.js has retrieved the document in question, we use thethen method to load the HTML content into cheerio.js to generate a list of links. Generally speaking, the links listed in a Confluence document usually follow the li span a selector pattern inside the body of the document. Here, we use the output variable to hold the list of links found in the retrieve data.....then(obj => {
$ = cheerio.load(obj.html.toString());
var output = '';
$('li span a').each(function() {
output += $(this).html() + '\n';
});
...Then, we write out the list of links we found in the Confluence document to our predetermined text file.
... fs.writeFileSync(confluenceSiteMap, output, 'utf8');
})
...Finally, we use the
catch method to report back any errors.... .catch(error => { console.error(error);
});
}
Wrapping up
With the script complete, we should save it something likeconfluenceSitemap.js. From there, we can execute this command to generate our list of links text file: node confluenceSitemap.js -u <username> -p <password> -s <spacekey> -f <links.txt>
Labels:
cheerio,
commander,
confluence,
css,
fs,
javascript,
nightmare.js,
scraping
Sunday, April 14, 2019
Comparing Published and Unpublished Documents in Confluence
Introduction
I recently had a challenge to upload over a thousand HTML documents to Confluence. I won't go into the details of what scripts I created using various Node.js modules, but I did want to share with you how I maintained a list of documents that were or were not published to Confluence.Requirements
You should be comfortable with a terminal interface, managing documents in Confluence, and Confluence CLI plugin.
Using the Confluence CLI
confluence --action getPageList --id "<parent page id>" --descendents > uploaded_docs.txtNote: the Confluence command itself needs to be setup as an alias in your Bash profile. The instructions for setting up the Confluence CLI plugin mentions how do some of this. My Bash alias looks something like this:
alias confluence="<path to confluence script>./confluence.sh --server <base Confluence URL> --user <user> --password <pasword>"
With that alias setup and a little forward thinking about how the space was going to be structured under a single document, I saved myself some time by parenting all the documents under this one ultimate parent document. (I wrote a script that handles that task as well which I'll share another time.) Having a single parent document, the CLI command reported back all the documents I needed to work with in one single execution of this command. Otherwise, I would have had to identify each parent document, execute this command on parent document, and tally up all the uploaded documents.
From here, with the two lists in hand, it was now a simple matter of finding the differences. There are several options out there to accomplish this but in the end, I just used Excel and used the conditional formatting feature to highlight the duplicates and the ones that weren't highlighted were the ones that needed to uploaded.
Maybe in the future I'll write a script that does this automatically from the two lists and share that process as well.
Thursday, March 14, 2019
Using Cheerio and Request to Scrape
Introduction
I've been heavily involved in content migration in the last few months. As a result, I've had look for solutions in pulling content from one site and push it into another. Often times, the source site wouldn't have an API to make my life easier. Enter cheerio and request npm modules. This tutorial will walk you through a basic routine of requesting a document and pulling content from a select set of elements.
Requirements
You should be fairly comfortable with JavaScript and CSS selectors in general and have some working knowledge of how Node.js works prior to digging into this tutorial.
Required npm packages
In this tutorial, we'll need to ensure the following packages have been install in your project directory:
Note: This tutorial was written with Node.js (version 10.11.0).
Setting up requirements
As mentioned earlier, this script will use cheerio to parse content with jQuery-like features and request to fetch content from a document. Next, we need to accept two arguments when executing this script: 1- A source document and 2- a selector to specify which element to pull content from.
const cheerio = require('cheerio');
const request = require('request');
const url = process.argv[2];
const selector = process.argv[3];
....
Input error handling
If the user doesn't supply an URL and a selector, the script should fail right away instead of attempting to extract something.
....
if (!url || !selector) {
console.log('You need to supply both an URL and a selector.');
process.exit(1);
} else {
<main routine>
}
Requesting and processing the body
The main routine of this script is to request a document and process it using cheerio so we get at select parts of the content. If there isn't any issue in requesting the document and the status is good, then we pass the body of the document to cheerio. From there, you can add whatever features you like to process the content.
request(url, (err, resp, body) => {
if (!err && resp.statusCode == 200) {
$ = cheerio.load(body.toString());
$(selector).each(function() {
// do something with the content
console.log($(this).html());
});
} else if (err) {
console.log(err);
}
});
Usage
With the script complete, we should complete the following steps to use it to pull content from the web.
- Save this file as
request.js. - Open a terminal in the same directory as
request.js. - Execute
node request <URL> <selector>replacing the URL with the web document you'd like to pull content from and replace selector with the element id or class you wish want to pull content from. For example, try this one:node request.js https://crudthedocs.blogspot.com/2019/01/scraping-web-document-using-nightmarejs.html '.post-title.entry-title' - Observe the output in the terminal.
Subscribe to:
Posts (Atom)