(dottedPath, dir, englishRoot)
| 124 | }) |
| 125 | |
| 126 | function getDataByDir(dottedPath, dir, englishRoot) { |
| 127 | const fullPath = ['data'] |
| 128 | |
| 129 | // Using English here because it doesn't matter. We just want to |
| 130 | // figure out how to turn `foo.version-3.4.deeper.key' into |
| 131 | // `['foo', 'version-3.4', 'deeper', 'key']` here and we'll need |
| 132 | // any directory to do that and English is always the most up-to-date. |
| 133 | // We need the getSmartSplit() as long as there's a chance that a |
| 134 | // directory or file inside data/ might contain a dot in the name, |
| 135 | // however the exception is the file names in data/release-notes/**/*.yml |
| 136 | // because it contains files that are just numbers like 3-7/0.yml and |
| 137 | // that can cause problems inside getSmartSplit(). |
| 138 | const split = dottedPath.startsWith('release-notes') |
| 139 | ? dottedPath.split('.') |
| 140 | : getSmartSplit(dottedPath) |
| 141 | |
| 142 | // For early-access data stuff, they're referred to as... |
| 143 | // |
| 144 | // {% data early-access.reusables.foo.bar %} |
| 145 | // |
| 146 | // When we "merge" in the early-access data, we put the whole directory |
| 147 | // within the root `data/` so it exists, on disk, as |
| 148 | // |
| 149 | // data/early-access/reusables/foo/bar.md |
| 150 | // |
| 151 | if (split[0] === 'early-access') { |
| 152 | fullPath.push(split.shift()) |
| 153 | } |
| 154 | const first = split[0] |
| 155 | |
| 156 | if (first === 'variables') { |
| 157 | const key = split.pop() |
| 158 | const basename = split.pop() |
| 159 | fullPath.push(...split) |
| 160 | fullPath.push(`${basename}.yml`) |
| 161 | const allData = getYamlContent(dir, fullPath.join(path.sep), englishRoot) |
| 162 | if (allData) { |
| 163 | const value = allData[key] |
| 164 | if (value) { |
| 165 | return matter(value).content |
| 166 | } |
| 167 | } else { |
| 168 | console.warn(`Unable to find variables Yaml file ${fullPath.join(path.sep)}`) |
| 169 | } |
| 170 | return |
| 171 | } |
| 172 | |
| 173 | if (first === 'reusables') { |
| 174 | const nakedname = split.pop() |
| 175 | fullPath.push(...split) |
| 176 | fullPath.push(`${nakedname}.md`) |
| 177 | const markdown = getMarkdownContent(dir, fullPath.join(path.sep), englishRoot) |
| 178 | return matter(markdown).content |
| 179 | } |
| 180 | |
| 181 | // E.g. {% data ui.pages.foo.bar %} |
| 182 | if (first === 'ui') { |
| 183 | const basename = split.shift() // i.e. 'ui' |
no test coverage detected