因为文档编辑需要,自己学着创建了一个Confluence自定义宏,大体情况是这样的,编写api文档的时候总要编辑url的地址,但是考虑到后期如果有服务器域名变更等的问题,可能就需要把所有文档里的接口地址都修改一遍,这样的操作想想都头皮发麻,于是想到了用宏来管理api的url链接。

首先我们分析下,url分为3个部分,域名(ip),端口,接口路径,所以我们需要的这个宏有对应的三个参数,其中域名部分因为不会变更,或者说需要变更的时候都要统一变更,所以这个部分可以做成一个selector。在简单的研习过Confluence的宏编写文档之后,于是写出了这个宏,代码如下

## Macro title: My Macro
## Macro has a body: Y or N
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: CheungQ
## Date created: dd/mm/yyyy
## Installed by: CheungQ

## This is an example macro
## @param Host:title=域名|type=enum|enumValues=www.mydomain.com|required=true|desc=域名
## @param Port:title=端口|type=string|required=true|desc=端口号|default=80
## @param Name:title=API|type=string|required=true|desc=API路径,不用带斜杠

<a target="_blank" href="http://$paramHost:$paramPort/$paramName">http://$paramHost:$paramPort/$paramName</a>

 

接下来还是看这个宏的效果吧

 

另外付下官方文档中的相关参数说明

 

The sections below describe each of the attributes in detail.

Attribute name

Description

Required / Recommended / Optional

(an unnamed, first attribute) A unique name for the parameter. The parameter name is the first attribute in the list. The name attribute itself does not have a name. See the section on name below. Required
multiple Specifies whether the parameter accepts multiple values. Defaults to false. Optional
required Specifies whether the user must enter information for this parameter. Defaults to false. Optional
default The default value for the parameter. Optional
type The field type for the parameter. See the section on type below. Recommended
desc The parameter description will appear in the macro browser. Optional
title The parameter title will appear in the macro browser. If you do not specify a title, Confluence will use the parameter name. Recommended

 

 

Parameter type

The field type for the parameter. If you do not specify a type, the default is string.

Parameter type

Description

boolean Displays a checkbox to the user and passes the value ‘true’ or ‘false’ to the macro as a string.
enum Offers a list of values for selection. You can specify the values to appear in a dropdown in the macro browser. Example of specifying the enum values:

## @param colour:title=Colour|type=enum|enumValues=Grey,Red,Yellow,Green

Note about i18n: Confluence does not support internationalisation of the enum values.The value the user sees is the one passed to the macro as the parameter value, with the capitalisation given. In this case ‘Grey’, ‘Red’, etc.

string A text field. This is the default type. Example with a required field:

## @param status:title=Status|type=string|required=true|desc=Status to display
confluence-content Offers a control allowing the user to search for a page or blog post. Example:

## @param page:title=Page|type=confluence-content|required=true|desc=Select a page do use
username Search for user.

## @param user:title=Username|type=username|desc=Select username to display
spacekey Offers a list of spaces for selection. Passes the space key to the macro. Example:

## @param space:title=Space|type=spacekey
date Confluence accepts this type, but currently treats it in the same way as ‘string’. Example:

## @param fromDate:title=From Date|type=date|desc=Date to start from. Format: dd/mm/YYYY 

Note about dates: A user can enter a date in any format, you should validate the date format in your user macro.

int Confluence accepts this type, but treats it in the same way as ‘string’. Example with a default value:

## @param numPosts:title=Number of Posts|type=int|default=15|desc=Number of posts to display
percentage Confluence accepts this type, but treats it in the same way as ‘string’. Example:

## @param pcent:title=Percentage|type=percentage|desc=Number of posts to display