Skip to content

Commit b12b21f

Browse files
authored
Merge pull request #6 from goatbytes/develop
Enhance Meta Tag Generation with Special Case Handling for Programming Languages
2 parents d4503d3 + f3ccdbc commit b12b21f

File tree

9 files changed

+6296
-0
lines changed

9 files changed

+6296
-0
lines changed

.art/Programming-Language-Logos.ai

+6,205
Large diffs are not rendered by default.

.github/workflows/ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ jobs:
2626
pip install mkdocs-minify-plugin
2727
pip install neoteroi-mkdocs
2828
pip install mkdocs-git-revision-date-localized-plugin
29+
# Install custom plugin
30+
pip install -e ./plugins/default_meta
2931
3032
- name: Build MkDocs site
3133
run: mkdocs build

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ node_modules/
1212
*.iws
1313
.idea/
1414

15+
# Python package metadata directories
16+
*.egg-info/
17+
__pycache__/
18+
1519
# Compiled SCSS
1620
*.css.map
1721
*.css.map/

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,19 @@ To build and serve the GoatStyles site locally, follow these instructions:
120120
- You can now make changes to the Markdown files. The site will automatically rebuild and
121121
refresh the browser page when you save changes.
122122
123+
## About GoatBytes.IO
124+
125+
![GoatBytesLogo](https://storage.googleapis.com/ktor-goatbytes.appspot.com/images/logo/1000h/goatbytes-logo-with-text.png)
126+
127+
At **GoatBytes.IO**, our mission is to develop secure software solutions that empower businesses to
128+
transform the world. With a focus on innovation and excellence, we strive to deliver cutting-edge
129+
products that meet the evolving needs of businesses across various industries.
130+
131+
[![GitHub](https://img.shields.io/badge/GitHub-GoatBytes-181717?logo=github)](https://github.com/goatbytes)
132+
[![Twitter](https://img.shields.io/badge/Twitter-GoatBytes-1DA1F2?logo=twitter)](https://twitter.com/goatbytes)
133+
[![LinkedIn](https://img.shields.io/badge/LinkedIn-GoatBytes-0077B5?logo=linkedin)](https://www.linkedin.com/company/goatbytes)
134+
[![Instagram](https://img.shields.io/badge/Instagram-GoatBytes.io-E4405F?logo=instagram)](https://www.instagram.com/goatbytes.io/)
135+
123136
## License
124137
125138
[GoatStyles][GH] is licensed under [Attribution-ShareAlike 4.0 International][LICENSE]

docs/assets/img/social.jpg

86.2 KB
Loading

mkdocs.yml

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ theme:
6666

6767
markdown_extensions:
6868
- admonition
69+
- meta
6970
- pymdownx.blocks.admonition
7071
- pymdownx.blocks.tab:
7172
alternate_style: true
@@ -89,6 +90,7 @@ markdown_extensions:
8990
- md_in_html
9091

9192
plugins:
93+
- default_meta
9294
- search
9395
- minify:
9496
minify_html: true

plugins/default_meta/__init__.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from mkdocs.plugins import BasePlugin
2+
from mkdocs.config import config_options
3+
import os
4+
5+
class DefaultMetaPlugin(BasePlugin):
6+
# A mapping for special case language names
7+
SPECIAL_CASES = {
8+
'typescript': 'TypeScript',
9+
'javascript': 'JavaScript',
10+
'csharp': 'C#',
11+
'objective-c': 'Objective-C',
12+
}
13+
14+
def format_language_name(self, filename):
15+
"""Format language name correctly based on filename."""
16+
language = os.path.splitext(filename)[0]
17+
return self.SPECIAL_CASES.get(language, language.capitalize())
18+
19+
def on_page_markdown(self, markdown, page, config, files):
20+
# Basic site info
21+
site_url = config.get('site_url', 'https://styles.goatbytes.io')
22+
default_image = f"{site_url}assets/img/social.jpg"
23+
24+
# Extract and format the language name from the file name
25+
language = self.format_language_name(os.path.basename(page.file.src_path))
26+
custom_title = f"{language} Code Style Guide | GoatStyles"
27+
custom_description = f"The official {language} code style guide used by GoatBytes.IO."
28+
29+
# Default meta tags with dynamic title and description
30+
defaults = [
31+
{'name': 'description', 'content': custom_description},
32+
{'property': 'og:type', 'content': 'website'},
33+
{'property': 'og:title', 'content': custom_title},
34+
{'property': 'og:description', 'content': custom_description},
35+
{'property': 'og:image', 'content': default_image},
36+
{'property': 'og:url', 'content': site_url},
37+
{'name': 'twitter:card', 'content': 'summary_large_image'},
38+
{'name': 'twitter:title', 'content': custom_title},
39+
{'name': 'twitter:description', 'content': custom_description},
40+
{'name': 'twitter:image', 'content': default_image},
41+
]
42+
43+
# Initialize or update page meta
44+
if 'meta' not in page.meta:
45+
page.meta['meta'] = defaults
46+
else:
47+
# Update existing tags or add defaults if missing
48+
existing_tags = {tag.get('name') or tag.get('property'): tag for tag in page.meta['meta']}
49+
for default in defaults:
50+
key = default.get('name') or default.get('property')
51+
if key not in existing_tags:
52+
page.meta['meta'].append(default)
53+
elif key in ['description', 'og:title', 'og:description', 'twitter:title', 'twitter:description']:
54+
# Update content for specific tags if they already exist
55+
existing_tags[key]['content'] = default['content']
56+
57+
return markdown

plugins/default_meta/setup.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from setuptools import setup, find_packages
2+
3+
setup(
4+
name='default_meta',
5+
version='0.1',
6+
packages=find_packages(),
7+
entry_points={
8+
'mkdocs.plugins': [
9+
'default_meta = default_meta:DefaultMetaPlugin',
10+
],
11+
}
12+
)

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mkdocs>=1.5.0

0 commit comments

Comments
 (0)