mkdocs-ultralytics-plugin 0.0.2__tar.gz → 0.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mkdocs-ultralytics-plugin
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: An MkDocs plugin that generates meta description and image tags based on the first paragraph and the first image in a page
5
5
  Author: Ultralytics
6
6
  Author-email: hello@ultralytics.com
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mkdocs-ultralytics-plugin
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: An MkDocs plugin that generates meta description and image tags based on the first paragraph and the first image in a page
5
5
  Author: Ultralytics
6
6
  Author-email: hello@ultralytics.com
@@ -6,6 +6,4 @@ mkdocs_ultralytics_plugin.egg-info/SOURCES.txt
6
6
  mkdocs_ultralytics_plugin.egg-info/dependency_links.txt
7
7
  mkdocs_ultralytics_plugin.egg-info/entry_points.txt
8
8
  mkdocs_ultralytics_plugin.egg-info/requires.txt
9
- mkdocs_ultralytics_plugin.egg-info/top_level.txt
10
- plugin/__init__.py
11
- plugin/images_and_descriptions.py
9
+ mkdocs_ultralytics_plugin.egg-info/top_level.txt
@@ -10,7 +10,7 @@ from setuptools import setup, find_packages
10
10
 
11
11
  setup(
12
12
  name='mkdocs-ultralytics-plugin',
13
- version='0.0.2',
13
+ version='0.0.3',
14
14
  description='An MkDocs plugin that generates meta description and image tags based on the first paragraph and the '
15
15
  'first image in a page',
16
16
  author='Ultralytics',
File without changes
@@ -1,49 +0,0 @@
1
- from bs4 import BeautifulSoup
2
- from mkdocs.plugins import BasePlugin
3
-
4
-
5
- class DescriptionImagePlugin(BasePlugin):
6
-
7
- def on_page_content(self, content, page, config, files):
8
- soup = BeautifulSoup(content, 'html.parser')
9
-
10
- # Extract the first paragraph text
11
- first_paragraph = soup.find('p')
12
- if first_paragraph:
13
- meta_description = first_paragraph.text.strip()
14
- page.meta['description'] = meta_description
15
-
16
- # Extract the first image URL
17
- first_image = soup.find('img')
18
- if first_image:
19
- meta_image = first_image['src']
20
- page.meta['image'] = meta_image
21
-
22
- return content
23
-
24
- def on_post_page(self, output, page, config):
25
- if 'description' not in page.meta and 'image' not in page.meta:
26
- return output
27
-
28
- # Update meta description
29
- soup = BeautifulSoup(output, 'html.parser')
30
- if 'description' in page.meta and (10 < len(page.meta['description']) < 500):
31
- meta_description = soup.find("meta", attrs={"name": "description"})
32
-
33
- if meta_description:
34
- print(f'START_DESCRIPTION\n{meta_description}\nEND_DESCRIPTION\n\n')
35
- meta_description['content'] = page.meta['description']
36
-
37
- # Update meta image
38
- if 'image' in page.meta:
39
- meta_image = soup.find("meta", attrs={"property": "og:image"})
40
-
41
- # If the meta image tag is not found, create and add it
42
- if not meta_image:
43
- meta_image = soup.new_tag("meta")
44
- meta_image.attrs.update({'property': 'og:image', 'content': page.meta['image']})
45
- soup.head.append(meta_image)
46
- else:
47
- meta_image['content'] = page.meta['image']
48
-
49
- return str(soup)