Confluence ページのタイニー リンクをプログラムを使用して生成する方法

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Fisheye および Crucible は除く

要約

Tiny links to Confluence pages are a good way to share content with other users. The tiny link is shown when you share a page using the share button and can be retrieved when you view the page information. They are generated based on the PageId after converting it to a byte array and encoding it in base64.

Confluence インスタンスで 1 つまたは複数のページのタイニー リンクをプログラム経由で生成する必要がある場合があります。このドキュメントではこのタスクについて説明します。

環境

Confluence Server または Data Center


ソリューション

本記事で説明している手順は、現時点でのものとなります。そのため、一部のお客様で特定の状況下で動作したという報告がありますが、正式にサポートされているわけではなく、お客様の特定のシナリオで動作することを保証するものではありません。

本番環境での実施の前に一通り非本番環境で検証し、成功しなかった場合にはサポートされている代替案にフォール バックしてください。

また、アトラシアン サポートのサポート対象外のご質問の場合には、Community もご活用ください。

We’ll generate the list of tiny links in two steps, getting all the pages, and generating each link.

Step 1: Get All Pages

First, get all pages in the instance with the following SQL query. This query can be adjusted to only return pages from a given space or user as well.

SELECT S.LOWERSPACEKEY, S.SPACENAME, TITLE, CONTENTID
FROM CONTENT
JOIN SPACES S on CONTENT.SPACEID = S.SPACEID
WHERE CONTENTTYPE = 'PAGE'
    AND PREVVER IS NULL
    AND CONTENT_STATUS = 'current';

Export the results of the query above to a CSV format. It should resemble the following:

ds,Demonstration Space,Welcome to Confluence,98319
ds,Demonstration Space,What is Confluence? (step 1 of 9),98320
ds,Demonstration Space,A quick look at the editor (step 2 of 9),98322
ds,Demonstration Space,Let's edit this page (step 3 of 9),98317
ds,Demonstration Space,Prettify the page with an image (step 4 of 9),98318
ds,Demonstration Space,Get serious with a table (step 5 of 9),98332
ds,Demonstration Space,Lay out your page (step 6 of 9),98321
ds,Demonstration Space,Learn the wonders of autoconvert (step 7 of 9),98314
ds,Demonstration Space,Tell people what you think in a comment (step 8 of 9),98305
ds,Demonstration Space,Share your page with a team member (step 9 of 9),98306

以降のソリューションは Perl スクリプトに基づいたものです。必要に応じて内容を変更したり、任意のコーディング言語に書き換えたりすることができます。

アルゴリズムの主な手順は次のとおりです。

  1. ページ ID を対応するバイト配列に変換します。
  2. base64 エンコーディングを使ってバイト配列を変換します。
  3. エンコードされた文字列に対して追加の処理を行います。

Make sure to replace the connieBaseUrl variable with the base URL for your instance. Place the CSV from step one next to the script, and rename it to pages.csv.

Confluence ページのタイニー リンクを作成するための Perl スクリプト
use MIME::Base64 qw(encode_base64);

my $connieBaseUrl = 'http://example.com/confluence'; ### Confluence Base URL
my $file = 'pages.csv';

open my $info, $file or die "Could not open $file: $!";

while( my $line = <$info>)  {   
    my @page = split(",",$line);
	my $pageID = @page[3];
	$pageID =~ s/^\s+|\s+$//g;


	my $tinyString = encode_base64(pack("L", $pageID)); ### the page ID must be encoded after converting it to a byte array
	my $actualTinyString = '';
	my $padding = 0;
	foreach my $c (split //, $tinyString)
	{
		if ($c eq '=')
		{ next; }
		if ($padding == 1 && $c eq 'A')
		{ next; }

		$padding = 0;
		if ($c eq '/')
		{
			$actualTinyString .= '-';
		}
		elsif ($c eq '+')
		{
			$actualTinyString .= '_';
		}
		elsif ($c eq "\n")
		{
			$actualTinyString .= '/';
		}
		else
		{
			$actualTinyString .= $c;
		}
	}

	my $tinyUrl = $connieBaseUrl . '/x/' . $actualTinyString;

	$line =~ s/^\s+|\s+$//g;
	print $line.",".$tinyUrl . "\n";
}

close $info;






最終更新日 2023 年 5 月 15 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.