This commit is contained in:
hoangvv 2025-02-28 02:35:19 +07:00
parent d9cb9d975f
commit 6b0c648c8e
9 changed files with 192 additions and 165 deletions

View File

@ -216,7 +216,6 @@ myst_enable_extensions = [
"fieldlist",
"html_admonition",
"html_image",
"linkify",
"replacements",
"smartquotes",
"strikethrough",

40
config.yaml Normal file
View File

@ -0,0 +1,40 @@
# -d, --dry-run Do not write/remove any files
# -R, --replace-files Remove parsed files
# -S, --stop-on-fail Stop on first failure
# -W, --raise-on-warning Raise exception on parsing warning
# -l, --language TEXT Language code for directive names [default:
# en]
# --sphinx / --no-sphinx Load sphinx. [default: sphinx]
# -e, --extensions TEXT A comma-separated list of sphinx extensions
# to load.
# -dd, --default-domain TEXT Default sphinx domain [default: py]
# -dr, --default-role TEXT Default sphinx role [default: convert to
# literal]
# -cp, --cite-prefix TEXT Prefix to add to citation references
# [default: cite]
# --consecutive-numbering / --no-consecutive-numbering
# Apply consecutive numbering to ordered lists
# [default: consecutive-numbering]
# --colon-fences / --no-colon-fences
# Use colon fences for directives with parsed
# content [default: colon-fences]
# --dollar-math / --no-dollar-math
# Convert math (where possible) to dollar-
# delimited math [default: dollar-math]
# -c, --conversions PATH YAML file mapping directives -> conversions
# --encoding TEXT Encoding for read/write [default: utf8]
# --config FILE YAML file to read default configuration from
# -h, --help Show this message and exit.
language: en
sphinx: true
extensions:
- sphinx.ext.intersphinx
- sphinx.ext.todo
- sphinx_tabs.tabs
default_conversion: parse_all
conversions:
docutils.parsers.rst.directives.images.image: parse_content
default_domain: py
consecutive_numbering: true
colon_fences: true
dollar_math: true

View File

@ -42,7 +42,7 @@ and then push them to GitHub. Skip this section and go to
affecting the main codebase. Skip this step if you work at Odoo.
4. ```{eval-rst}
.. include:: install_git.rst
.. include:: install_git.md
```
5. Configure Git to identify yourself as the author of your future contributions. Enter the same

View File

@ -64,7 +64,7 @@ to make changes from the GitHub interface.
without affecting the main codebase. Skip this step if you work at Odoo.
04. ```{eval-rst}
.. include:: install_git.rst
.. include:: install_git.md
```
05. Configure Git to identify yourself as the author of your future contributions. Enter the same

View File

@ -33,17 +33,17 @@ Avoid duplicating content whenever possible; if a topic is already documented on
:::
:::{important}
When deleting or moving a `.rst` file, update the corresponding text file in the
When deleting or moving a `.md` file, update the corresponding text file in the
{file}`redirects` folder based on your branch's version (e.g., {file}`17.0.txt`). To do so, add a
new line at the bottom of the relevant section (e.g., `# applications/sales`). On this line,
first, add the redirection entry point with the old file location, followed by a space, and then
add the exit point with the new or relevant file location. For example, if moving the file
{file}`unsplash.rst` from {file}`applications/websites/website/configuration` to
{file}`unsplash.md` from {file}`applications/websites/website/configuration` to
{file}`applications/general/integrations`, add the following entry under the section
`# applications/websites`:
```text
applications/websites/website/configuration/unsplash.rst applications/general/integrations/unsplash.rst
applications/websites/website/configuration/unsplash.md applications/general/integrations/unsplash.md
```
:::
@ -302,7 +302,7 @@ A **media filename**:
Each RST file has its own folder for storing media files. The folder's name must be the same as the
RST file's name.
For example, the document {file}`doc_filename.rst` refers to two images that are placed in the
For example, the document {file}`doc_filename.md` refers to two images that are placed in the
folder `doc_filename`.
```
@ -310,7 +310,7 @@ folder `doc_filename`.
│ └── doc_filename
│ │ └── screenshot-tips.gif
│ │ └── awesome-filename.png
│ └── doc_filename.rst
│ └── doc_filename.md
```
:::{note}

View File

@ -72,22 +72,22 @@ location *relative* to that of the source document.
│ │ │ └── sales
│ │ │ │ └── products_prices
│ │ │ │ │ └── products
│ │ │ │ │ │ └── import.rst
│ │ │ │ │ │ └── variants.rst
│ │ │ │ │ └── prices.rst
│ │ │ │ │ │ └── import.md
│ │ │ │ │ │ └── variants.md
│ │ │ │ │ └── prices.md
A reference to :file:`prices.rst` and :file:`variants.rst` could be made from :file:`import.rst`
A reference to :file:`prices.md` and :file:`variants.md` could be made from :file:`import.md`
as follows:
#. Absolute:
- `documentation/content/applications/sales/sales/products_prices/prices.rst`
- `documentation/content/applications/sales/sales/products_prices/products/variants.rst`
- `documentation/content/applications/sales/sales/products_prices/prices.md`
- `documentation/content/applications/sales/sales/products_prices/products/variants.md`
#. Relative:
- `../prices.rst`
- `variants.rst`
- `../prices.md`
- `variants.md`
```
(contributing-rst-update-targets)=

View File

@ -81,15 +81,15 @@ The root element of form views is `form`.
Optional attributes can be added to the root element `form` to customize the view.
```{eval-rst}
.. include:: view_architectures/root_attribute_string.rst
.. include:: view_architectures/root_attribute_string.md
```
```{eval-rst}
.. include:: view_architectures/root_attribute_create.rst
.. include:: view_architectures/root_attribute_create.md
```
```{eval-rst}
.. include:: view_architectures/root_attribute_edit.rst
.. include:: view_architectures/root_attribute_edit.md
```
```{eval-rst}
@ -104,7 +104,7 @@ Optional attributes can be added to the root element `form` to customize the vie
```
```{eval-rst}
.. include:: view_architectures/root_attribute_delete.rst
.. include:: view_architectures/root_attribute_delete.md
```
```{eval-rst}
@ -163,7 +163,7 @@ exist with different values for the `required` attribute.
The `field` element can have the following attributes:
```{eval-rst}
.. include:: view_architectures/field_attribute_name.rst
.. include:: view_architectures/field_attribute_name.md
```
```{eval-rst}
@ -179,7 +179,7 @@ The `field` element can have the following attributes:
```
```{eval-rst}
.. include:: view_architectures/field_attribute_string.rst
.. include:: view_architectures/field_attribute_string.md
```
```{eval-rst}
@ -214,19 +214,19 @@ The `field` element can have the following attributes:
```
```{eval-rst}
.. include:: view_architectures/field_attribute_readonly.rst
.. include:: view_architectures/field_attribute_readonly.md
```
```{eval-rst}
.. include:: view_architectures/field_attribute_required.rst
.. include:: view_architectures/field_attribute_required.md
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_invisible.rst
.. include:: view_architectures/generic_attribute_invisible.md
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_groups.rst
.. include:: view_architectures/generic_attribute_groups.md
```
```{eval-rst}
@ -313,7 +313,7 @@ The `field` element can have the following attributes:
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_class.rst
.. include:: view_architectures/generic_attribute_class.md
```
```{eval-rst}
@ -432,11 +432,11 @@ The `label` element can have the following attributes:
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_class.rst
.. include:: view_architectures/generic_attribute_class.md
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_invisible.rst
.. include:: view_architectures/generic_attribute_invisible.md
```
(reference-view-architectures-form-button)=
@ -453,39 +453,39 @@ The `label` element can have the following attributes:
The `button` element can have the following attributes:
```{eval-rst}
.. include:: view_architectures/button_attribute_type.rst
.. include:: view_architectures/button_attribute_type.md
```
```{eval-rst}
.. include:: view_architectures/button_attribute_name.rst
.. include:: view_architectures/button_attribute_name.md
```
```{eval-rst}
.. include:: view_architectures/button_attribute_string.rst
.. include:: view_architectures/button_attribute_string.md
```
```{eval-rst}
.. include:: view_architectures/button_attribute_icon.rst
.. include:: view_architectures/button_attribute_icon.md
```
```{eval-rst}
.. include:: view_architectures/button_attribute_help.rst
.. include:: view_architectures/button_attribute_help.md
```
```{eval-rst}
.. include:: view_architectures/button_attribute_context.rst
.. include:: view_architectures/button_attribute_context.md
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_groups.rst
.. include:: view_architectures/generic_attribute_groups.md
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_invisible.rst
.. include:: view_architectures/generic_attribute_invisible.md
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_class.rst
.. include:: view_architectures/generic_attribute_class.md
```
```{eval-rst}
@ -671,7 +671,7 @@ The `group` element can have the following attributes:
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_invisible.rst
.. include:: view_architectures/generic_attribute_invisible.md
```
:::{admonition} Possible structure and representation of its rendering
@ -759,7 +759,7 @@ The `page` element can have the following attributes:
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_invisible.rst
.. include:: view_architectures/generic_attribute_invisible.md
```
:::{admonition} Possible structure and representation of its rendering
@ -1112,11 +1112,11 @@ The `app` element can have the following attributes:
% todo: document attribute notApp
```{eval-rst}
.. include:: view_architectures/generic_attribute_groups.rst
.. include:: view_architectures/generic_attribute_groups.md
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_invisible.rst
.. include:: view_architectures/generic_attribute_invisible.md
```
(reference-view-architectures-settings-block)=
@ -1163,11 +1163,11 @@ The `block` element can have the following attributes:
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_groups.rst
.. include:: view_architectures/generic_attribute_groups.md
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_invisible.rst
.. include:: view_architectures/generic_attribute_invisible.md
```
(reference-view-architectures-settings-setting)=
@ -1279,11 +1279,11 @@ The `<setting>` element can have the following attributes:
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_groups.rst
.. include:: view_architectures/generic_attribute_groups.md
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_invisible.rst
.. include:: view_architectures/generic_attribute_invisible.md
```
(reference-view-architectures-list)=
@ -1315,19 +1315,19 @@ The root element of list views is `list` (the previous name was `tree`).
Optional attributes can be added to the root element `list` to customize the view.
```{eval-rst}
.. include:: view_architectures/root_attribute_string.rst
.. include:: view_architectures/root_attribute_string.md
```
```{eval-rst}
.. include:: view_architectures/root_attribute_create.rst
.. include:: view_architectures/root_attribute_create.md
```
```{eval-rst}
.. include:: view_architectures/root_attribute_edit.rst
.. include:: view_architectures/root_attribute_edit.md
```
```{eval-rst}
.. include:: view_architectures/root_attribute_delete.rst
.. include:: view_architectures/root_attribute_delete.md
```
```{eval-rst}
@ -1409,11 +1409,11 @@ Optional attributes can be added to the root element `list` to customize the vie
```
```{eval-rst}
.. include:: view_architectures/root_attribute_default_group_by.rst
.. include:: view_architectures/root_attribute_default_group_by.md
```
```{eval-rst}
.. include:: view_architectures/root_attribute_default_order.rst
.. include:: view_architectures/root_attribute_default_order.md
```
```{eval-rst}
@ -1476,7 +1476,7 @@ Optional attributes can be added to the root element `list` to customize the vie
```
```{eval-rst}
.. include:: view_architectures/root_attribute_sample.rst
.. include:: view_architectures/root_attribute_sample.md
```
(reference-view-architectures-list-components)=
@ -1510,11 +1510,11 @@ Using the same field multiple times in a list view is not supported
The `field` element can have the following attributes:
```{eval-rst}
.. include:: view_architectures/field_attribute_name.rst
.. include:: view_architectures/field_attribute_name.md
```
```{eval-rst}
.. include:: view_architectures/field_attribute_string.rst
.. include:: view_architectures/field_attribute_string.md
```
```{eval-rst}
@ -1547,23 +1547,23 @@ The `field` element can have the following attributes:
```
```{eval-rst}
.. include:: view_architectures/field_attribute_readonly.rst
.. include:: view_architectures/field_attribute_readonly.md
```
```{eval-rst}
.. include:: view_architectures/field_attribute_required.rst
.. include:: view_architectures/field_attribute_required.md
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_invisible.rst
.. include:: view_architectures/generic_attribute_invisible.md
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_column_invisible.rst
.. include:: view_architectures/generic_attribute_column_invisible.md
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_groups.rst
.. include:: view_architectures/generic_attribute_groups.md
```
```{eval-rst}
@ -1679,43 +1679,43 @@ form view, as they cannot be grouped.
The `button` element can have the following attributes:
```{eval-rst}
.. include:: view_architectures/button_attribute_type.rst
.. include:: view_architectures/button_attribute_type.md
```
```{eval-rst}
.. include:: view_architectures/button_attribute_name.rst
.. include:: view_architectures/button_attribute_name.md
```
```{eval-rst}
.. include:: view_architectures/button_attribute_string.rst
.. include:: view_architectures/button_attribute_string.md
```
```{eval-rst}
.. include:: view_architectures/button_attribute_icon.rst
.. include:: view_architectures/button_attribute_icon.md
```
```{eval-rst}
.. include:: view_architectures/button_attribute_help.rst
.. include:: view_architectures/button_attribute_help.md
```
```{eval-rst}
.. include:: view_architectures/button_attribute_context.rst
.. include:: view_architectures/button_attribute_context.md
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_groups.rst
.. include:: view_architectures/generic_attribute_groups.md
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_invisible.rst
.. include:: view_architectures/generic_attribute_invisible.md
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_column_invisible.rst
.. include:: view_architectures/generic_attribute_column_invisible.md
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_class.rst
.. include:: view_architectures/generic_attribute_class.md
```
:::{admonition} Possible structure and representation of its rendering
@ -2011,7 +2011,7 @@ The `field` element can have the following attributes:
```
```{eval-rst}
.. include:: view_architectures/field_attribute_string.rst
.. include:: view_architectures/field_attribute_string.md
```
```{eval-rst}
@ -2077,11 +2077,11 @@ The `field` element can have the following attributes:
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_groups.rst
.. include:: view_architectures/generic_attribute_groups.md
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_invisible.rst
.. include:: view_architectures/generic_attribute_invisible.md
```
:::{admonition} Possible structure and representation of its rendering
@ -2307,11 +2307,11 @@ The `filter` element can have the following attributes:
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_invisible.rst
.. include:: view_architectures/generic_attribute_invisible.md
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_groups.rst
.. include:: view_architectures/generic_attribute_groups.md
```
```{eval-rst}
@ -2455,7 +2455,7 @@ attributes:
```
```{eval-rst}
.. include:: view_architectures/field_attribute_string.rst
.. include:: view_architectures/field_attribute_string.md
```
```{eval-rst}
@ -2481,7 +2481,7 @@ attributes:
```
```{eval-rst}
.. include:: view_architectures/generic_attribute_groups.rst
.. include:: view_architectures/generic_attribute_groups.md
```
```{eval-rst}
@ -2673,27 +2673,27 @@ still be opened by the user.
Optional attributes can be added to the root element `kanban` to customize the view.
```{eval-rst}
.. include:: view_architectures/root_attribute_string.rst
.. include:: view_architectures/root_attribute_string.md
```
```{eval-rst}
.. include:: view_architectures/root_attribute_create.rst
.. include:: view_architectures/root_attribute_create.md
```
```{eval-rst}
.. include:: view_architectures/root_attribute_edit.rst
.. include:: view_architectures/root_attribute_edit.md
```
```{eval-rst}
.. include:: view_architectures/root_attribute_delete.rst
.. include:: view_architectures/root_attribute_delete.md
```
```{eval-rst}
.. include:: view_architectures/root_attribute_default_group_by.rst
.. include:: view_architectures/root_attribute_default_group_by.md
```
```{eval-rst}
.. include:: view_architectures/root_attribute_default_order.rst
.. include:: view_architectures/root_attribute_default_order.md
```
```{eval-rst}
@ -2851,7 +2851,7 @@ Optional attributes can be added to the root element `kanban` to customize the v
```
```{eval-rst}
.. include:: view_architectures/root_attribute_sample.rst
.. include:: view_architectures/root_attribute_sample.md
```
(reference-view-architectures-kanban-components)=
@ -2900,7 +2900,7 @@ Inside those templates, the `field` element allows to render a field. It can hav
attributes:
```{eval-rst}
.. include:: view_architectures/field_attribute_name.rst
.. include:: view_architectures/field_attribute_name.md
```
By default, field nodes are replaced by a `span` containing their formatted value, unless the
@ -3345,7 +3345,7 @@ The main additions of qweb-as-view to the basic qweb-as-template are:
context:
```{eval-rst}
.. rst-class:: o-definition-list
.. container:: o-definition-list
```
`model`
@ -3383,7 +3383,7 @@ record groups. Its root element is `<graph>` which can take the following
attributes:
```{eval-rst}
.. rst-class:: o-definition-list
.. container:: o-definition-list
```
`type` (optional)
@ -3410,14 +3410,14 @@ attributes:
: string displayed in the breadcrumbs when redirecting to list view.
```{eval-rst}
.. include:: view_architectures/root_attribute_sample.rst
.. include:: view_architectures/root_attribute_sample.md
```
The only allowed element within a graph view is `field` which can have the
following attributes:
```{eval-rst}
.. rst-class:: o-definition-list
.. container:: o-definition-list
```
`name` (mandatory)
@ -3475,7 +3475,7 @@ The pivot view is used to visualize aggregations as a [pivot table]. Its root
element is `<pivot>` which can take the following attributes:
```{eval-rst}
.. rst-class:: o-definition-list
.. container:: o-definition-list
```
`disable_linking` (optional)
@ -3501,7 +3501,7 @@ The only allowed element within a pivot view is `field` which can have the
following attributes:
```{eval-rst}
.. rst-class:: o-definition-list
.. container:: o-definition-list
```
`name` (mandatory)
@ -3520,7 +3520,7 @@ following attributes:
aggregated value within a group. Possible values are:
```{eval-rst}
.. rst-class:: o-definition-list
.. container:: o-definition-list
```
`row` (default)
@ -3548,7 +3548,7 @@ following attributes:
such as fields in different units, e.g. € and \$).
```{eval-rst}
.. include:: view_architectures/root_attribute_sample.rst
.. include:: view_architectures/root_attribute_sample.md
```
The measures are automatically generated from the model fields; only the
@ -3608,14 +3608,14 @@ calendar view are:
Disable/enable record deletion on the view through the **Action** dropdown.
.. rst-class:: o-definition-list
.. container:: o-definition-list
``date_start`` (required)
name of the record's field holding the start date for the event
```
```{eval-rst}
.. rst-class:: o-definition-list
.. container:: o-definition-list
```
`date_start` (required)
@ -3697,7 +3697,7 @@ calendar view are:
Fields can have additional attributes:
```{eval-rst}
.. rst-class:: o-definition-list
.. container:: o-definition-list
```
`invisible`
@ -3751,7 +3751,7 @@ The root element of the Activity view is `<activity>`, it accepts the following
attributes:
```{eval-rst}
.. rst-class:: o-definition-list
.. container:: o-definition-list
```
`string` (mandatory)
@ -3761,7 +3761,7 @@ attributes:
Possible children of the view element are:
```{eval-rst}
.. rst-class:: o-definition-list
.. container:: o-definition-list
```
`field`
@ -3772,7 +3772,7 @@ Possible children of the view element are:
Possible attributes are:
```{eval-rst}
.. rst-class:: o-definition-list
.. container:: o-definition-list
```
`name` (required)
@ -3791,7 +3791,7 @@ Possible children of the view element are:
(see {ref}`reference/view_architectures/kanban` for more details):
```{eval-rst}
.. rst-class:: o-definition-list
.. container:: o-definition-list
```
`widget`
@ -3838,7 +3838,7 @@ The root element of the Cohort view is \<cohort>, it accepts the following
attributes:
```{eval-rst}
.. rst-class:: o-definition-list
.. container:: o-definition-list
```
`string` (mandatory)
@ -3888,7 +3888,7 @@ attributes:
main use is for hiding a field from the selectable measures:
```{eval-rst}
.. rst-class:: o-definition-list
.. container:: o-definition-list
```
`name` (mandatory)
@ -3913,7 +3913,7 @@ attributes:
: alternate representations for a field's display.
```{eval-rst}
.. include:: view_architectures/root_attribute_sample.rst
.. include:: view_architectures/root_attribute_sample.md
```
(reference-view-architectures-grid)=
@ -4274,14 +4274,14 @@ take the following attributes:
Disable/enable record deletion on the view through the **Action** dropdown.
.. rst-class:: o-definition-list
.. container:: o-definition-list
``date_start`` (required)
name of the field providing the start datetime of the event for each
```
```{eval-rst}
.. rst-class:: o-definition-list
.. container:: o-definition-list
```
`date_start` (required)
@ -4466,7 +4466,7 @@ take the following attributes:
<reference/qweb/javascript>` and provides the following context variables:
```{eval-rst}
.. rst-class:: o-definition-list
.. container:: o-definition-list
```
`widget`
@ -4517,7 +4517,7 @@ take the following attributes:
will display the users avatars next to their names when grouped by user_id.
```{eval-rst}
.. include:: view_architectures/root_attribute_sample.rst
.. include:: view_architectures/root_attribute_sample.md
```
(reference-view-architectures-map)=
@ -4545,7 +4545,7 @@ As soon as a valid [MapBox] token is provided in the general settings the view s
The view's root element is `<map>`. It can have the following attributes:
```{eval-rst}
.. rst-class:: o-definition-list
.. container:: o-definition-list
```
`res_partner`
@ -4583,7 +4583,7 @@ The view's root element is `<map>`. It can have the following attributes:
The `<map>` element can contain multiple `<field>` elements. Each `<field>` element is interpreted as a line in the pin's popup. The field's attributes are the following:
```{eval-rst}
.. rst-class:: o-definition-list
.. container:: o-definition-list
```
`name`

View File

@ -1,64 +1,55 @@
#!/bin/bash
# Enable stricter error handling
set -euo pipefail
# Check arguments
if [[ $# -ne 2 ]]; then
echo "Usage: $0 <source_folder> <target_folder>" >&2
exit 1
fi
readonly SOURCE_DIR="$1"
SOURCE_DIR=$(realpath "$1") # Normalize source path
readonly TARGET_DIR="$2"
readonly TEMP_ERROR=$(mktemp)
readonly LOG_FILE="/tmp/convert2md_$$.log"
# Trap to clean up temp files on exit
trap 'rm -f "$TEMP_ERROR" "$LOG_FILE"' EXIT
# Validate inputs
validate_inputs() {
[[ ! -d "$SOURCE_DIR" ]] && {
echo "Error: Source directory '$SOURCE_DIR' does not exist." >&2
exit 1
}
mkdir -p "$TARGET_DIR" || {
echo "Error: Could not create target directory '$TARGET_DIR'." >&2
exit 1
}
command -v rst2myst >/dev/null 2>&1 || {
echo "Error: rst2myst is not installed. Install with 'pip install rst-to-myst'." >&2
exit 1
}
[[ ! -d "$SOURCE_DIR" ]] && { echo "Error: Source directory '$SOURCE_DIR' does not exist." >&2; exit 1; }
mkdir -p "$TARGET_DIR" || { echo "Error: Could not create target directory '$TARGET_DIR'." >&2; exit 1; }
command -v rst2myst >/dev/null 2>&1 || { echo "Error: rst2myst not installed. Use 'pip install rst-to-myst'." >&2; exit 1; }
}
# Process RST files
process_rst_file() {
local rst_file="$1"
local relative_path="${rst_file#$SOURCE_DIR/}"
local md_file_name="${relative_path%.rst}.md"
local target_file="$TARGET_DIR/$md_file_name"
local target_dir=$(dirname "$target_file")
mkdir -p "$target_dir" || {
echo "Error: Could not create directory '$target_dir' for '$rst_file'" >&2
mkdir -p "$target_dir" || { echo "Error: Could not create '$target_dir' for '$rst_file'" >&2; return 1; }
if rst2myst stream --config config.yaml "$rst_file" > "$target_file" 2>>"$TEMP_ERROR"; then
# Replace 'rst-class' with 'container' and '.rst' with '.md' in content
sed -i 's/rst-class/container/g; s/\.rst/.md/g' "$target_file" 2>>"$TEMP_ERROR" || {
echo "Error: Failed to modify content of '$target_file'" >&2
return 1
}
if rst2myst stream "$rst_file" > "$target_file" 2>>"$TEMP_ERROR"; then
echo "Converted: $rst_file -> $target_file" | tee -a "$LOG_FILE"
echo "converted" >> "$TEMP_ERROR"
return 0
else
echo "Failed to convert: $rst_file" >&2
cat "$TEMP_ERROR" >&2
echo "failed" >> "$TEMP_ERROR"
return 1
fi
}
# Copy non-RST files
copy_non_rst_file() {
local file="$1"
local relative_path="${file#$SOURCE_DIR/}"
local target_file="$TARGET_DIR/$relative_path"
local target_dir=$(dirname "$target_file")
mkdir -p "$target_dir" && cp -p "$file" "$target_file" 2>/dev/null && {
mkdir -p "$target_dir" && cp -p "$file" "$target_file" 2>>"$TEMP_ERROR" && {
# Replace 'rst-class' with 'container' and '.rst' with '.md' in content
sed -i 's/rst-class/container/g; s/\.rst/.md/g' "$target_file" 2>>"$TEMP_ERROR" || {
echo "Error: Failed to modify content of '$target_file'" >&2
return 1
}
echo "Copied: $file -> $target_file" | tee -a "$LOG_FILE"
return 0
} || {
@ -71,46 +62,42 @@ main() {
validate_inputs
echo "Starting conversion process..." | tee "$LOG_FILE"
# Count total RST files
readonly TOTAL_RST_FILES=$(find "$SOURCE_DIR" -type f -name "*.rst" | wc -l)
echo "Found $TOTAL_RST_FILES RST files to process" | tee -a "$LOG_FILE"
# Log all files found
mapfile -t RST_FILES < <(find "$SOURCE_DIR" -type f -name "*.rst" 2>>"$LOG_FILE")
mapfile -t NON_RST_FILES < <(find "$SOURCE_DIR" -type f ! -name "*.rst" 2>>"$LOG_FILE")
echo "Found ${#RST_FILES[@]} RST files and ${#NON_RST_FILES[@]} non-RST files" | tee -a "$LOG_FILE"
printf '%s\n' "${RST_FILES[@]}" | sed 's/^/RST: /' >> "$LOG_FILE"
printf '%s\n' "${NON_RST_FILES[@]}" | sed 's/^/Non-RST: /' >> "$LOG_FILE"
local parallel_jobs=$(( $(nproc) / 2 )) # Use half the CPU cores to avoid overload
# Export functions for xargs
local parallel_jobs=$(( $(nproc) / 2 ))
export -f process_rst_file copy_non_rst_file
export SOURCE_DIR TARGET_DIR TEMP_ERROR LOG_FILE
# Process RST files with limited parallelism
find "$SOURCE_DIR" -type f -name "*.rst" -print0 | xargs -0 -P "$parallel_jobs" -I {} bash -c 'process_rst_file "{}"' || {
echo "Warning: Some RST processing failed. Check $LOG_FILE for details." >&2
# Process RST files
printf '%s\0' "${RST_FILES[@]}" | xargs -0 -P "$parallel_jobs" -I {} bash -c 'process_rst_file "{}"' || {
echo "Warning: Some RST processing failed. Check $LOG_FILE." >&2
}
# Process non-RST files with limited parallelism
find "$SOURCE_DIR" -type f ! -name "*.rst" -print0 | xargs -0 -P "$parallel_jobs" -I {} bash -c 'copy_non_rst_file "{}"' || {
echo "Warning: Some file copies failed. Check $LOG_FILE for details." >&2
# Process non-RST files
printf '%s\0' "${NON_RST_FILES[@]}" | xargs -0 -P "$parallel_jobs" -I {} bash -c 'copy_non_rst_file "{}"' || {
echo "Warning: Some file copies failed. Check $LOG_FILE." >&2
}
# Count results from log
readonly SUCCESSFUL_CONVERSIONS=$(grep -c "^Converted:" "$LOG_FILE")
readonly FAILED_CONVERSIONS=$(grep -c "^Failed to convert:" "$LOG_FILE")
# Summary
echo "Conversion and copy process complete." | tee -a "$LOG_FILE"
echo "Total RST files found: $TOTAL_RST_FILES" | tee -a "$LOG_FILE"
echo "RST files successfully converted: $SUCCESSFUL_CONVERSIONS" | tee -a "$LOG_FILE"
echo "RST files failed to convert: $FAILED_CONVERSIONS" | tee -a "$LOG_FILE"
echo "Non-RST files copied: $(grep -c "^Copied:" "$LOG_FILE")" | tee -a "$LOG_FILE"
local successful=$(grep -c "^Converted:" "$LOG_FILE")
local failed=$(grep -c "^Failed to convert:" "$LOG_FILE")
local copied=$(grep -c "^Copied:" "$LOG_FILE")
echo "Conversion complete." | tee -a "$LOG_FILE"
echo "RST files found: ${#RST_FILES[@]}" | tee -a "$LOG_FILE"
echo "RST files converted: $successful" | tee -a "$LOG_FILE"
echo "RST files failed: $failed" | tee -a "$LOG_FILE"
echo "Non-RST files copied: $copied" | tee -a "$LOG_FILE"
# Check if all files were processed
if [[ $((TOTAL_RST_FILES)) != $((SUCCESSFUL_CONVERSIONS + FAILED_CONVERSIONS)) ]]; then
echo "Warning: Some RST files might not have been processed!" >&2
if [[ ${#RST_FILES[@]} -ne $((successful + failed)) ]]; then
echo "Error: ${#RST_FILES[@]} RST files found, but only $((successful + failed)) processed!" >&2
exit 1
fi
[[ $FAILED_CONVERSIONS -gt 0 ]] && {
echo "Note: Some RST conversions failed. See $LOG_FILE for details." >&2
exit 1
}
[[ $failed -gt 0 ]] && { echo "Note: $failed RST conversions failed. See $LOG_FILE." >&2; exit 1; }
}
main "$@"

View File

@ -112,3 +112,4 @@ paramiko ; python_version > '3.10'
proxmoxer ; python_version > '3.10'
requests ; python_version > '3.10'
google_auth ; python_version > '3.10'
esbonio