Skip to content

Commit

Permalink
Merge pull request #6 from goatbytes/develop
Browse files Browse the repository at this point in the history
Enhance Meta Tag Generation with Special Case Handling for Programming Languages
  • Loading branch information
jaredrummler committed Apr 6, 2024
2 parents d4503d3 + f3ccdbc commit b12b21f
Show file tree
Hide file tree
Showing 9 changed files with 6,296 additions and 0 deletions.
6,205 changes: 6,205 additions & 0 deletions .art/Programming-Language-Logos.ai

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
pip install mkdocs-minify-plugin
pip install neoteroi-mkdocs
pip install mkdocs-git-revision-date-localized-plugin
# Install custom plugin
pip install -e ./plugins/default_meta
- name: Build MkDocs site
run: mkdocs build
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ node_modules/
*.iws
.idea/

# Python package metadata directories
*.egg-info/
__pycache__/

# Compiled SCSS
*.css.map
*.css.map/
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ To build and serve the GoatStyles site locally, follow these instructions:
- You can now make changes to the Markdown files. The site will automatically rebuild and
refresh the browser page when you save changes.

## About GoatBytes.IO

![GoatBytesLogo](https://storage.googleapis.com/ktor-goatbytes.appspot.com/images/logo/1000h/goatbytes-logo-with-text.png)

At **GoatBytes.IO**, our mission is to develop secure software solutions that empower businesses to
transform the world. With a focus on innovation and excellence, we strive to deliver cutting-edge
products that meet the evolving needs of businesses across various industries.

[![GitHub](https://img.shields.io/badge/GitHub-GoatBytes-181717?logo=github)](https://github.com/goatbytes)
[![Twitter](https://img.shields.io/badge/Twitter-GoatBytes-1DA1F2?logo=twitter)](https://twitter.com/goatbytes)
[![LinkedIn](https://img.shields.io/badge/LinkedIn-GoatBytes-0077B5?logo=linkedin)](https://www.linkedin.com/company/goatbytes)
[![Instagram](https://img.shields.io/badge/Instagram-GoatBytes.io-E4405F?logo=instagram)](https://www.instagram.com/goatbytes.io/)

## License

[GoatStyles][GH] is licensed under [Attribution-ShareAlike 4.0 International][LICENSE]
Expand Down
Binary file added docs/assets/img/social.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ theme:

markdown_extensions:
- admonition
- meta
- pymdownx.blocks.admonition
- pymdownx.blocks.tab:
alternate_style: true
Expand All @@ -89,6 +90,7 @@ markdown_extensions:
- md_in_html

plugins:
- default_meta
- search
- minify:
minify_html: true
Expand Down
57 changes: 57 additions & 0 deletions plugins/default_meta/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from mkdocs.plugins import BasePlugin
from mkdocs.config import config_options
import os

class DefaultMetaPlugin(BasePlugin):
# A mapping for special case language names
SPECIAL_CASES = {
'typescript': 'TypeScript',
'javascript': 'JavaScript',
'csharp': 'C#',
'objective-c': 'Objective-C',
}

def format_language_name(self, filename):
"""Format language name correctly based on filename."""
language = os.path.splitext(filename)[0]
return self.SPECIAL_CASES.get(language, language.capitalize())

def on_page_markdown(self, markdown, page, config, files):
# Basic site info
site_url = config.get('site_url', 'https://styles.goatbytes.io')
default_image = f"{site_url}assets/img/social.jpg"

# Extract and format the language name from the file name
language = self.format_language_name(os.path.basename(page.file.src_path))
custom_title = f"{language} Code Style Guide | GoatStyles"
custom_description = f"The official {language} code style guide used by GoatBytes.IO."

# Default meta tags with dynamic title and description
defaults = [
{'name': 'description', 'content': custom_description},
{'property': 'og:type', 'content': 'website'},
{'property': 'og:title', 'content': custom_title},
{'property': 'og:description', 'content': custom_description},
{'property': 'og:image', 'content': default_image},
{'property': 'og:url', 'content': site_url},
{'name': 'twitter:card', 'content': 'summary_large_image'},
{'name': 'twitter:title', 'content': custom_title},
{'name': 'twitter:description', 'content': custom_description},
{'name': 'twitter:image', 'content': default_image},
]

# Initialize or update page meta
if 'meta' not in page.meta:
page.meta['meta'] = defaults
else:
# Update existing tags or add defaults if missing
existing_tags = {tag.get('name') or tag.get('property'): tag for tag in page.meta['meta']}
for default in defaults:
key = default.get('name') or default.get('property')
if key not in existing_tags:
page.meta['meta'].append(default)
elif key in ['description', 'og:title', 'og:description', 'twitter:title', 'twitter:description']:
# Update content for specific tags if they already exist
existing_tags[key]['content'] = default['content']

return markdown
12 changes: 12 additions & 0 deletions plugins/default_meta/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from setuptools import setup, find_packages

setup(
name='default_meta',
version='0.1',
packages=find_packages(),
entry_points={
'mkdocs.plugins': [
'default_meta = default_meta:DefaultMetaPlugin',
],
}
)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mkdocs>=1.5.0

0 comments on commit b12b21f

Please sign in to comment.