Skip to content
This repository was archived by the owner on Dec 7, 2021. It is now read-only.

Commit c8f2dfc

Browse files
committed
First attempt at content
Proof of concept of using the content generation system described in <https://phabricator.wikimedia.org/T276708#7360487>. * documents are described in data/documents/*.yaml * categories are described in data/categories/*.yaml * YAML descriptions are gathered by our macros module and exposed as context data. * A jinja macro is provided for selecting category information from the context. Content taken from https://github.com/apaskulin/wmf-dev-portal-draft mockup. Bug: T276708
1 parent 24e980b commit c8f2dfc

File tree

14 files changed

+229
-9
lines changed

14 files changed

+229
-9
lines changed

data/categories/api-reading.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: api-reading
3+
title: Reading APIs
4+
description: Fetch pages from Wikipedia, Wiktionary, Wikivoyage, and more.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: Wikipedia featured content API
3+
description: Get daily featured articles, most read pages, and more.
4+
links:
5+
- url: https://wikimedia.org/api/rest_v1/#/Feed%20content%20availability
6+
label: See language availability
7+
- url: https://public.paws.wmcloud.org/User:APaskulin_(WMF)/API-Portal/wikimedia-api-portal-featured-content.ipynb
8+
label: Read the tutorial
9+
- url: https://en.wikipedia.org/api/rest_v1/
10+
label: Try out the interactive docs
11+
categories:
12+
- api-reading

data/documents/mobile-api.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Mobile API
3+
description: Get pages in mobile format.
4+
links:
5+
- url: https://en.wikipedia.org/api/rest_v1/#/Mobile
6+
label: Try out the interactive docs
7+
categories:
8+
- api-reading

data/documents/page-api.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: Page API
3+
description: Get pages by title on any Wikimedia project.
4+
links:
5+
- url: https://www.mediawiki.org/wiki/API:Article_ideas_generator
6+
label: Read the tutorial
7+
- url: https://www.mediawiki.org/wiki/API:Parsing_wikitext
8+
label: Read the docs on mediawiki.org
9+
categories:
10+
- api-reading

data/documents/search-api.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: Search API
3+
description: Find articles in Wikipedia, images in Commons, and more.
4+
links:
5+
- url: https://public.paws.wmcloud.org/User:APaskulin_(WMF)/en-wikipedia-search.ipynb
6+
label: Read the tutorial
7+
- url: https://www.mediawiki.org/wiki/API:REST_API
8+
label: Read the docs on mediawiki.org
9+
categories:
10+
- api-reading

macros/__init__.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,43 @@
1515
#
1616
# You should have received a copy of the GNU General Public License along with
1717
# Wikimedia Developer Portal. If not, see <http://www.gnu.org/licenses/>.
18+
import os
19+
from pathlib import Path
20+
21+
import yaml
22+
1823

1924
def define_env(env):
2025
"""Setup local variables, macros, and filters for mkdocs-macros-plugin."""
2126

27+
chatter = env.start_chatting('category')
28+
root_dir = Path(env.conf.config_file_path).parent
29+
data_dir = root_dir / "data"
30+
categories_dir = data_dir / "categories"
31+
documents_dir = data_dir / "documents"
32+
33+
cat_tree = {}
34+
for cat in categories_dir.glob("**/*.yaml"):
35+
with cat.open() as f:
36+
for doc in yaml.safe_load_all(f):
37+
if "category" in doc:
38+
doc["documents"] = []
39+
cat_tree[doc["category"]] = doc
40+
else:
41+
chatter("{} missing category".format(cat))
42+
for document in documents_dir.glob("**/*.yaml"):
43+
with document.open() as f:
44+
for doc in yaml.safe_load_all(f):
45+
for category in doc.get("categories"):
46+
if category in cat_tree:
47+
cat_tree[category]["documents"].append(doc)
48+
else:
49+
chatter(
50+
"{}: unknown category '{}'".format(doc, category)
51+
)
52+
env.variables.categories = cat_tree
53+
2254
@env.macro
23-
def say_hello(s):
24-
return "Hello {}".format(s)
55+
def category(name):
56+
"""Output a category."""
57+
return env.variables.categories.get(name, {})

mkdocs.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ site_description: Portal for discovering technical documentation about Wikimedia
44
site_author: Wikimedia Foundation and contributors
55
copyright: Copyright &copy; 2021 Wikimedia Foundation and contributors
66

7-
docs_dir: src/portal
7+
nav:
8+
- Get started: 'index.md'
9+
- Wikimedia APIs: 'api/index.md'
10+
11+
docs_dir: src
812
theme:
913
name: material
1014
language: en
@@ -57,7 +61,10 @@ markdown_extensions:
5761
plugins:
5862
- search:
5963
lang: en
60-
- macros
64+
- macros:
65+
module_name: macros
66+
include_dir: data/includes
67+
verbose: true
6168
- mdpo:
6269
locale_dir: locale
6370
lc_messages: true

src/api/index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Wikimedia APIs
2+
3+
Wikimedia offers several public APIs to access content and data from Wikipedia and other free knowledge projects.
4+
5+
## Reading APIs
6+
7+
Fetch freely licensed content from Wikimedia projects.
8+
9+
[Learn more](reading/)

src/api/reading.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: Reading APIs
3+
...
4+
{% set cat = category("api-reading") %}
5+
6+
# {{ cat.title }}
7+
8+
{{ cat.description }}
9+
10+
{% for doc in cat.documents %}
11+
## {{ doc.title }}
12+
13+
{{ doc.description }}
14+
15+
{% for link in doc.links %}
16+
* [{{ link.label }}]({{ link.url }})
17+
{% endfor %}
18+
{% endfor %}

src/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@
33
Learn about, interact with, and contribute to the open source technology that
44
powers [Wikipedia](https://www.wikipedia.org/) and other [Wikimedia projects](https://wikimediafoundation.org/our-work/wikimedia-projects/).
55

6-
Hello world!
6+
## Use Wikimedia APIs
7+
8+
Public API access to content from Wikipedia and other free knowledge projects
9+
10+
[Learn more](api/)

0 commit comments

Comments
 (0)