|
| 1 | +.. _style-guide-sharedinclude: |
| 2 | + |
| 3 | +============== |
| 4 | +Shared Include |
| 5 | +============== |
| 6 | + |
| 7 | +The ``sharedinclude`` directive lets you source content from a file located in |
| 8 | +the MongoDB internal `docs-shared <https://github.com/10gen/docs-shared>`__ |
| 9 | +repository. Use this directive when you need to keep the same content in sync |
| 10 | +for multiple sets of documentation or branches of a documentation set. |
| 11 | + |
| 12 | +This page uses the following terms: |
| 13 | + |
| 14 | +External file |
| 15 | + Content committed to the ``docs-shared`` repository that other documentation |
| 16 | + repositories can source. |
| 17 | + |
| 18 | +Sourcing file |
| 19 | + Content in a documentation repository that uses a ``sharedinclude`` |
| 20 | + directive to pull content from an external file. |
| 21 | + |
| 22 | +Placeholder |
| 23 | + Variable that identifies where replacement content should be inserted. |
| 24 | + These variables are represented as a name surrounded by the ``|`` (pipe) |
| 25 | + character. Add them in the external file and define the replacement content |
| 26 | + in the sourcing file. |
| 27 | + |
| 28 | +.. tip:: |
| 29 | + |
| 30 | + The ``sharedinclude`` directive extends the ``include`` directive. |
| 31 | + While the ``include`` directive allows you to source content from the |
| 32 | + branch of the repository in which it is used, the ``sharedinclude`` |
| 33 | + directive is hard-coded to reference external files from the |
| 34 | + `10gen/docs-shared <https://github.com/10gen/docs-shared/>`__ |
| 35 | + private GitHub repository. |
| 36 | + |
| 37 | + |
| 38 | +Setup |
| 39 | +----- |
| 40 | + |
| 41 | +You must ensure the ``sharedinclude_root`` setting in the documentation |
| 42 | +repository's ``snooty.toml`` configuration file is set to the shared |
| 43 | +content repository URL. This URL must point to the unprocessed version of the |
| 44 | +files currently served from the ``raw.githubusercontent.com`` domain. |
| 45 | + |
| 46 | +For example, if the external files that your docs repository file references |
| 47 | +is on the ``main`` branch of ``docs-shared``, your docs repository |
| 48 | +``snooty.toml`` configuration entry should resemble the following line: |
| 49 | + |
| 50 | +.. code-block:: |
| 51 | + |
| 52 | + sharedinclude_root = "https://raw.githubusercontent.com/10gen/docs-shared/main/" |
| 53 | + |
| 54 | +Snooty reports an error if you attempt to use ``sharedinclude`` without |
| 55 | +configuring this setting. |
| 56 | + |
| 57 | + |
| 58 | +Syntax |
| 59 | +------ |
| 60 | + |
| 61 | +Add the ``sharedinclude`` directive to the sourcing file to include content |
| 62 | +from the external file. Specify the path of the external file relative to the |
| 63 | +``docs-shared`` base directory, omitting the leading slash. |
| 64 | + |
| 65 | +For example, if the file path from the root of the ``docs-shared`` repository |
| 66 | +is ``drivers/compatibility-tables/c.rst``, the {+rst-abbrev+} in the sourcing |
| 67 | +file should include the following code: |
| 68 | + |
| 69 | +.. code-block:: rst |
| 70 | + :caption: sourcing_file.txt in a documentation repository |
| 71 | + :copyable: false |
| 72 | + |
| 73 | + .. _sharedinclude:: drivers/compatibility-tables/c.rst |
| 74 | + |
| 75 | +The external file includes replacement variables in the form of |
| 76 | +``|variable-name|``. You can define the replacement values in sourcing files |
| 77 | +to customize segments of the page. |
| 78 | + |
| 79 | +For example, suppose the ``docs-shared`` file ``language.rst`` contained the |
| 80 | +following content with a replacement variable called ``|driver-name|``: |
| 81 | + |
| 82 | +.. code-block:: rst |
| 83 | + :caption: language.rst in the docs-shared repository |
| 84 | + :copyable: false |
| 85 | + |
| 86 | + The following table shows the compatibility between different versions of |
| 87 | + the |driver-name| driver and the |driver-language|: |
| 88 | + |
| 89 | +The sourcing file could resemble the following code: |
| 90 | + |
| 91 | +.. code-block:: rst |
| 92 | + :caption: compatibility-table.txt sourcing file in the documentation repository |
| 93 | + :copyable: false |
| 94 | + |
| 95 | + .. _sharedinclude:: drivers/compatibility-tables/language.rst |
| 96 | + |
| 97 | + .. replacement:: driver-name |
| 98 | + |
| 99 | + PyMongo |
| 100 | + |
| 101 | + .. replacement:: driver-language |
| 102 | + |
| 103 | + Python language |
| 104 | + |
| 105 | +The published page displays the following text: |
| 106 | + |
| 107 | +.. code-block:: rst |
| 108 | + :copyable: false |
| 109 | + |
| 110 | + The following table shows the compatibility between different versions of |
| 111 | + the PyMongo driver and the Python language: |
| 112 | + |
| 113 | +Snooty reports a warning or error if the sourcing file is missing any |
| 114 | +replacement variables present in the external file. |
| 115 | + |
| 116 | +Placeholders in Inline Context |
| 117 | +`````````````````````````````` |
| 118 | + |
| 119 | +An **inline context** describes the positioning of placeholders as adjacent to |
| 120 | +other paragraph text. If the placeholder is in an inline context, you can |
| 121 | +replace it with markup elements, including the following types: |
| 122 | + |
| 123 | +- Unformatted text |
| 124 | +- Formatted text such as ``monospace``, **emphasis**, or *italic* |
| 125 | +- Links |
| 126 | + |
| 127 | +You cannot replace variable placeholders in inline contexts with elements |
| 128 | +such as lists, code blocks, includes, and headers. If you need to |
| 129 | +source these elements from a ``sharedinclude``, ensure the placeholders |
| 130 | +are in a block context as described in the next section. |
| 131 | + |
| 132 | +For example, suppose you want to source content from an external file, located |
| 133 | +at ``dbx/fundamentals/agg-operators.rst`` in the ``docs-shared`` repository |
| 134 | +that contains the following content: |
| 135 | + |
| 136 | +.. code-block:: rst |
| 137 | + :caption: dbx/fundamentals/agg-operators.rst external file in docs_shared |
| 138 | + :copyable: false |
| 139 | + |
| 140 | + To learn more about **aggregation operators**, see the |
| 141 | + |learn-agg-operator-docs|. |
| 142 | + |
| 143 | +In the sourcing file, you can use the following placeholder replacement |
| 144 | +in the ``sharedinclude`` directive: |
| 145 | + |
| 146 | +.. code-block:: rst |
| 147 | + :caption: agg-operators.txt sourcing file in a documentation repository |
| 148 | + :copyable: false |
| 149 | + |
| 150 | + .. sharedinclude:: dbx/fundamentals/agg-operators.rst |
| 151 | + |
| 152 | + .. replacement:: learn-agg-operator-docs |
| 153 | + |
| 154 | + Aggregation Operations page in the |
| 155 | + :server:`MongoDB Server documentation </aggregation>` |
| 156 | + |
| 157 | +The published page renders as if the sourcing file contained the following |
| 158 | +{+rst-abbrev+}: |
| 159 | + |
| 160 | +.. code-block:: rst |
| 161 | + :copyable: false |
| 162 | + |
| 163 | + To learn more about **aggregation operators**, see the Aggregation Operations |
| 164 | + page in the :server:`MongoDB Server documentation </aggregation>`. |
| 165 | + |
| 166 | +Placeholders in Block Context |
| 167 | +````````````````````````````` |
| 168 | + |
| 169 | +A **block context** describes the positioning of placeholders as |
| 170 | +separated from paragraph text by line breaks. You can replace placeholders in |
| 171 | +a block context with most inline or block {+rst-abbrev+} elements, including |
| 172 | +the following types: |
| 173 | + |
| 174 | +- Titles |
| 175 | +- Code blocks |
| 176 | +- Anchors |
| 177 | +- Admonitions |
| 178 | + |
| 179 | +For example, suppose you want to source content from an external file located |
| 180 | +at ``dbx/fundamentals/agg-operators.rst`` in the ``docs-shared`` repository, |
| 181 | +which contains the following content: |
| 182 | + |
| 183 | +.. code-block:: rst |
| 184 | + :caption: dbx/fundamentals/agg-operators.rst external file in docs_shared |
| 185 | + :copyable: false |
| 186 | + |
| 187 | + The following section demonstrates how to use aggregation operators to build |
| 188 | + an aggregation pipeline. |
| 189 | + |
| 190 | + |aggregation-operators-example| |
| 191 | + |
| 192 | + To learn more, see ... |
| 193 | + |
| 194 | +In the sourcing file, you can use the following placeholder replacement |
| 195 | +in the ``sharedinclude`` directive: |
| 196 | + |
| 197 | +.. code-block:: rst |
| 198 | + :caption: agg-expression-operators.txt sourcing file in a documentation repository |
| 199 | + :copyable: false |
| 200 | + |
| 201 | + .. sharedinclude:: dbx/fundamentals/agg-operators.rst |
| 202 | + |
| 203 | + .. replacement:: aggregation-operators-example |
| 204 | + |
| 205 | + .. _expression-operators-example: |
| 206 | + |
| 207 | + Expression Operators Example |
| 208 | + ```````````````````````````` |
| 209 | + |
| 210 | + Expression operators are similar to functions and can take an array |
| 211 | + of arguments as shown in the following format: |
| 212 | + |
| 213 | + .. code-block:: |
| 214 | + |
| 215 | + { <operator>: [ <argument1>, <argument2> ... ] } |
| 216 | + |
| 217 | +The published page renders as if the sourcing file contained the following {+rst-abbrev+}: |
| 218 | + |
| 219 | +.. code-block:: rst |
| 220 | + :copyable: false |
| 221 | + |
| 222 | + The following section demonstrates how to use aggregation operators to build |
| 223 | + an aggregation pipeline. |
| 224 | + |
| 225 | + .. _expression-operators-example: |
| 226 | + |
| 227 | + Expression Operators Example |
| 228 | + ```````````````````````````` |
| 229 | + |
| 230 | + Expression operators are similar to functions and can take an array |
| 231 | + of arguments as shown in the following format: |
| 232 | + |
| 233 | + .. code-block:: |
| 234 | + |
| 235 | + { <operator>: [ <argument1>, <argument2> ... ] } |
| 236 | + |
| 237 | + To learn more, see ... |
0 commit comments