Skip to content

Commit bf41279

Browse files
authored
chore(docs): bring docs contents from magma/magma (#2)
Signed-off-by: Lucas Amaral <[email protected]>
1 parent 3e60615 commit bf41279

File tree

1,018 files changed

+110679
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,018 files changed

+110679
-0
lines changed

Makefile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.PHONY: dev precommit precommit_fix help
2+
3+
dev: ## Start local docs server with live reload
4+
make -C docusaurus dev
5+
6+
precommit: ## Run docs precommit checks
7+
make -C readmes precommit
8+
9+
precommit_fix: ## Try to fix existing precommit issues
10+
make -C readmes precommit_fix
11+
12+
sidebar_check: ## Check if all pages are implemented with sidebars for 1.7.0, 1.8.0, and latest
13+
python3 check_sidebars.py
14+
15+
# Ref: https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
16+
help: ## Show documented commands
17+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}'

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
# magma-documentation
2+
23
A standalone home for work on documentation for Magma, in order to make check-ins less work
4+
5+
## Magma Documentation
6+
7+
This document provides pointers for those looking to make documentation changes for the Magma project
8+
9+
- [Documentation Overview](https://github.com/magma/magma/wiki/Contributing-Documentation) for general documentation information
10+
- `make help` for specific commands

check_sidebars.py

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Copyright 2023 The Magma Authors.
4+
5+
This source code is licensed under the BSD-style license found in the
6+
LICENSE file in the root directory of this source tree.
7+
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
"""
14+
import json
15+
import os
16+
from typing import Set
17+
18+
exceptions = {
19+
"proposals/README",
20+
"proposals/p004_fua-restrict-feature",
21+
"proposals/p006_subscriber_state_view",
22+
"proposals/p008_inbound_roaming_with_SubscriberDb",
23+
"proposals/p006_mandatory_integration_tests_for_each_PR.md",
24+
"proposals/p010_vendor_neutral_dp",
25+
"proposals/p011_intra_agw_mobility",
26+
"proposals/p012_resource-tagging",
27+
"proposals/sim_integration",
28+
"proposals/p021_mme_migrate_to_c++",
29+
"proposals/p022_enodebd_enhancements",
30+
"proposals/p023_magma_gtp_gateway",
31+
"proposals/p024_magma_settlement_service",
32+
"proposals/p025_magma_cdr_availability",
33+
"proposals/p026_magma_inbound_roaming_extensions",
34+
"proposals/qos_enforcement",
35+
}
36+
37+
38+
def get_implemented_sidebar_pages(version: str = "latest") -> Set[str]:
39+
"""
40+
Scrape the relevant sidebar.json file to get all the pages
41+
that are implemented in the sidebar.
42+
43+
Args:
44+
version (str): The version of the docs to check. Defaults to "latest".
45+
46+
Returns:
47+
Set[str]: A set of sidebar pages that are implemented.
48+
"""
49+
version_prefix = _get_version_prefix(version)
50+
implemented_sidebar_pages = _extract_sidebar_pages(
51+
sidebar_json_path=_get_sidebar_json_path(version),
52+
version_prefix=version_prefix,
53+
)
54+
implemented_sidebar_pages = _remove_version_prefix(
55+
implemented_sidebar_pages=implemented_sidebar_pages,
56+
version_prefix=version_prefix,
57+
)
58+
return implemented_sidebar_pages
59+
60+
61+
def get_all_pages(version: str = "latest") -> Set[str]:
62+
"""
63+
Scrape the relevant docs folder to get all relevant page ids.
64+
65+
Args:
66+
version (str): The version of the docs to check. Defaults to "latest".
67+
68+
Returns:
69+
Set[str]: A set of all pages that are available for this version.
70+
"""
71+
readme_path = _get_readme_path(version)
72+
all_pages = set()
73+
for root, _, filenames in os.walk(readme_path):
74+
for filename in filenames:
75+
if filename.endswith('.md'):
76+
doc_id = _extract_doc_id(filename, root, _get_version_prefix(version))
77+
all_pages.add(root.replace(f'{readme_path}/', '') + '/' + doc_id)
78+
return all_pages
79+
80+
81+
def _extract_sidebar_pages(sidebar_json_path, version_prefix):
82+
implemented_sidebar_pages = set()
83+
with open(sidebar_json_path) as f:
84+
sidebars = json.load(f)[f'{version_prefix}docs']
85+
for v in sidebars.values():
86+
if isinstance(v[0], str):
87+
implemented_sidebar_pages = implemented_sidebar_pages.union(set(v))
88+
else:
89+
for item in v:
90+
implemented_sidebar_pages = implemented_sidebar_pages.union(set(item['ids']))
91+
return implemented_sidebar_pages
92+
93+
94+
def _remove_version_prefix(implemented_sidebar_pages, version_prefix):
95+
for page in implemented_sidebar_pages:
96+
if page.startswith(version_prefix):
97+
implemented_sidebar_pages.remove(page)
98+
implemented_sidebar_pages.add(page.replace(version_prefix, ''))
99+
return implemented_sidebar_pages
100+
101+
102+
def _get_readme_path(version):
103+
if version == 'latest':
104+
return 'readmes'
105+
return f'docusaurus/versioned_docs/version-{version}'
106+
107+
108+
def _get_sidebar_json_path(version):
109+
if version == 'latest':
110+
return 'docusaurus/sidebars.json'
111+
return f'docusaurus/versioned_sidebars/version-{version}-sidebars.json'
112+
113+
114+
def _get_version_prefix(version):
115+
if version == 'latest':
116+
return ''
117+
return f'version-{version}-'
118+
119+
120+
def _extract_doc_id(filename, root, version_prefix):
121+
path = os.path.join(root, filename)
122+
doc_id = ""
123+
with open(path) as f:
124+
lines = f.readlines()
125+
if lines and lines[0].startswith('---'):
126+
for line in lines:
127+
if line.startswith('id: '):
128+
doc_id = line.replace(f'id: {version_prefix}', '').rstrip('\n')
129+
break
130+
else:
131+
doc_id = filename.replace('.md', '')
132+
return doc_id
133+
134+
135+
def main():
136+
"""
137+
Check if all pages are implemented in the sidebar.
138+
"""
139+
versions = ("latest", "1.8.0", "1.7.0")
140+
pages_not_implemented = {v: set() for v in versions}
141+
for v in versions:
142+
all_pages = get_all_pages(version=v)
143+
sidebar_pages = get_implemented_sidebar_pages(version=v)
144+
for doc in sorted(all_pages):
145+
if doc not in sidebar_pages.union(exceptions):
146+
pages_not_implemented[v].add(doc)
147+
148+
sidebars_missing = False
149+
for v in versions:
150+
if pages_not_implemented[v]:
151+
sidebars_missing = True
152+
print(f"Missing pages for {v}: {pages_not_implemented[v]}")
153+
if sidebars_missing:
154+
exit(1)
155+
156+
157+
if __name__ == '__main__':
158+
main()

docusaurus/.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/node_modules

docusaurus/Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2023 The Magma Authors.
2+
3+
# This source code is licensed under the BSD-style license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
# Unless required by applicable law or agreed to in writing, software
7+
# distributed under the License is distributed on an "AS IS" BASIS,
8+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
# See the License for the specific language governing permissions and
10+
# limitations under the License.
11+
12+
FROM node:14
13+
14+
WORKDIR /app/website
15+
16+
COPY package.json /app/website/package.json
17+
RUN yarn install

docusaurus/Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.PHONY: dev
2+
3+
dev:
4+
./create_docusaurus_website.sh

docusaurus/core/Footer.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright 2020 The Magma Authors.
3+
*
4+
* This source code is licensed under the BSD-style license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
14+
const React = require('react');
15+
16+
class Footer extends React.Component {
17+
docUrl(doc, language) {
18+
const baseUrl = this.props.config.baseUrl;
19+
const docsUrl = this.props.config.docsUrl;
20+
const docsPart = `${docsUrl ? `${docsUrl}/` : ''}`;
21+
const langPart = `${language ? `${language}/` : ''}`;
22+
return `${baseUrl}${docsPart}${langPart}${doc}`;
23+
}
24+
25+
pageUrl(doc, language) {
26+
const baseUrl = this.props.config.baseUrl;
27+
return baseUrl + (language ? `${language}/` : '') + doc;
28+
}
29+
30+
render() {
31+
return (
32+
<footer className="nav-footer" id="footer">
33+
<section className="copyright">{this.props.config.copyright}</section>
34+
</footer>
35+
);
36+
}
37+
}
38+
39+
module.exports = Footer;
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
# Copyright 2020 The Magma Authors.
4+
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
set -e
15+
16+
function exit_timeout() {
17+
echo ''
18+
docker compose logs docusaurus
19+
echo ''
20+
echo "Timed out after ${1}s waiting for Docusaurus container to build. See logs above for more info."
21+
echo "Possible remedies:"
22+
echo ' - Remove node_modules directory (rm -rf node_modules) and try again.'
23+
exit 1
24+
}
25+
26+
# spin until localhost:3000 returns HTTP code 200.
27+
function spin() {
28+
maxsec=300
29+
spin='-\|/'
30+
i=0
31+
while [[ "$(curl -s -o /dev/null -w '%{http_code}' localhost:3000)" != "200" ]]; do
32+
[[ $i == "$maxsec" ]] && exit_timeout $i
33+
i=$(( i + 1 ))
34+
j=$(( i % 4 ))
35+
printf "\r%s" "${spin:$j:1}"
36+
sleep 1
37+
done
38+
printf "\r \n"
39+
}
40+
41+
docker compose down
42+
docker build -t magma_docusaurus .
43+
docker compose --compatibility up -d
44+
45+
echo ''
46+
echo 'NOTE: README changes will live-reload. Sidebar changes require re-running this script.'
47+
echo ''
48+
echo 'Waiting for Docusaurus site to come up...'
49+
echo 'If you want to follow the build logs, run docker compose logs -f docusaurus'
50+
spin
51+
echo 'Navigate to http://localhost:3000/ to see the docs.'
52+
53+
xdg-open 'http://localhost:3000/docs/next/basics/introduction.html' || true

docusaurus/docker-compose.publish.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: "3.7"
2+
3+
services:
4+
docusaurus:
5+
# Don't install or start anything, will do that manually during publish
6+
command: bash -c 'while true ; do echo $$(date) ; sleep 10 ; done'

docusaurus/docker-compose.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: "3.7"
2+
3+
services:
4+
docusaurus:
5+
volumes:
6+
- ./../docusaurus:/app/website
7+
- ./../readmes:/app/docs
8+
ports:
9+
- 3000:3000/tcp
10+
- 35729:35729/tcp
11+
image: magma_docusaurus
12+
command: bash -c 'yarn install && yarn start'

0 commit comments

Comments
 (0)