1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

DOCS: [GitBook] Code block caption (#1999)

Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
Jeffrey Cafferata
2023-01-29 19:02:56 +01:00
committed by GitHub
parent 0051b41720
commit 45ad35e68a
2 changed files with 16 additions and 10 deletions

View File

@ -19,17 +19,18 @@ the currently-loading file (which may not be the file where the
is interpreted relative to the program's working directory at the time is interpreted relative to the program's working directory at the time
of the call. of the call.
{% code title="dnsconfig.js" %}
```javascript ```javascript
// dnsconfig.js
require('kubernetes/clusters.js'); require('kubernetes/clusters.js');
D("mydomain.net", REG, PROVIDER, D("mydomain.net", REG, PROVIDER,
IncludeKubernetes() IncludeKubernetes()
); );
``` ```
{% endcode %}
{% code title="kubernetes/clusters.js" %}
```javascript ```javascript
// kubernetes/clusters.js
require('./clusters/prod.js'); require('./clusters/prod.js');
require('./clusters/dev.js'); require('./clusters/dev.js');
@ -37,29 +38,32 @@ function IncludeKubernetes() {
return [includeK8Sprod(), includeK8Sdev()]; return [includeK8Sprod(), includeK8Sdev()];
} }
``` ```
{% endcode %}
{% code title="kubernetes/clusters/prod.js" %}
```javascript ```javascript
// kubernetes/clusters/prod.js
function includeK8Sprod() { function includeK8Sprod() {
return [ return [
// ... // ...
]; ];
} }
``` ```
{% endcode %}
{% code title="kubernetes/clusters/dev.js" %}
```javascript ```javascript
// kubernetes/clusters/dev.js
function includeK8Sdev() { function includeK8Sdev() {
return [ return [
// ... // ...
]; ];
} }
``` ```
{% endcode %}
You can also use it to require JSON files and initialize variables with it: You can also use it to require JSON files and initialize variables with it:
{% code title="dnsconfig.js" %}
```javascript ```javascript
// dnsconfig.js
var domains = require('./domain-ip-map.json') var domains = require('./domain-ip-map.json')
for (var domain in domains) { for (var domain in domains) {
@ -68,14 +72,16 @@ for (var domain in domains) {
); );
} }
``` ```
{% endcode %}
{% code title="domain-ip-map.json" %}
```javascript ```javascript
// domain-ip-map.json
{ {
"mydomain.net": "1.1.1.1", "mydomain.net": "1.1.1.1",
"myotherdomain.org": "5.5.5.5" "myotherdomain.org": "5.5.5.5"
} }
``` ```
{% endcode %}
# Future # Future

View File

@ -30,17 +30,17 @@ require_glob("./domains/", false);
One more important thing to note: `require_glob()` is as smart as `require()` is. It loads files always relative to the JavaScript One more important thing to note: `require_glob()` is as smart as `require()` is. It loads files always relative to the JavaScript
file where it's being executed in. Let's go with an example, as it describes it better: file where it's being executed in. Let's go with an example, as it describes it better:
`dnscontrol.js`: {% code title="dnsconfig.js" %}
```javascript ```javascript
require("domains/index.js"); require("domains/index.js");
``` ```
{% endcode %}
`domains/index.js`: {% code title="domains/index.js" %}
```javascript ```javascript
require_glob("./user1/"); require_glob("./user1/");
``` ```
{% endcode %}
This will now load files being present underneath `./domains/user1/` and **NOT** at below `./domains/`, as `require_glob()` This will now load files being present underneath `./domains/user1/` and **NOT** at below `./domains/`, as `require_glob()`
is called in the subfolder `domains/`. is called in the subfolder `domains/`.