Skip to content

Commit b219d6b

Browse files
authored
added social thumbnail for docs (#11083)
1 parent 6c1bee7 commit b219d6b

File tree

2 files changed

+75
-48
lines changed

2 files changed

+75
-48
lines changed

docs/source/conf.py

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,24 @@
1414
#
1515
import os
1616
import sys
17-
sys.path.insert(0, os.path.abspath('../../src'))
17+
18+
sys.path.insert(0, os.path.abspath("../../src"))
1819

1920

2021
# -- Project information -----------------------------------------------------
2122

22-
project = u'transformers'
23-
copyright = u'2020, The Hugging Face Team, Licenced under the Apache License, Version 2.0'
24-
author = u'huggingface'
23+
project = "transformers"
24+
copyright = "2020, The Hugging Face Team, Licenced under the Apache License, Version 2.0"
25+
author = "huggingface"
2526

2627
# The short X.Y version
27-
version = u''
28+
version = ""
2829
# The full version, including alpha/beta/rc tags
29-
release = u'4.5.0.dev0'
30+
release = "4.5.0.dev0"
3031

3132

3233
# Prefix link to point to master, comment this during version release and uncomment below line
33-
extlinks = {'prefix_link': ('https://github.com/huggingface/transformers/blob/master/%s', '')}
34+
extlinks = {"prefix_link": ("https://github.com/huggingface/transformers/blob/master/%s", "")}
3435
# Prefix link to always point to corresponding version, uncomment this during version release
3536
# extlinks = {'prefix_link': ('https://github.com/huggingface/transformers/blob/v'+ release + '/%s', '')}
3637

@@ -44,27 +45,28 @@
4445
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
4546
# ones.
4647
extensions = [
47-
'sphinx.ext.autodoc',
48-
'sphinx.ext.extlinks',
49-
'sphinx.ext.coverage',
50-
'sphinx.ext.napoleon',
51-
'recommonmark',
52-
'sphinx.ext.viewcode',
53-
'sphinx_markdown_tables',
54-
'sphinx_copybutton'
48+
"sphinx.ext.autodoc",
49+
"sphinx.ext.extlinks",
50+
"sphinx.ext.coverage",
51+
"sphinx.ext.napoleon",
52+
"recommonmark",
53+
"sphinx.ext.viewcode",
54+
"sphinx_markdown_tables",
55+
"sphinxext.opengraph",
56+
"sphinx_copybutton",
5557
]
5658

5759
# Add any paths that contain templates here, relative to this directory.
58-
templates_path = ['_templates']
60+
templates_path = ["_templates"]
5961

6062
# The suffix(es) of source filenames.
6163
# You can specify multiple suffix as a list of string:
6264
#
63-
source_suffix = ['.rst', '.md']
65+
source_suffix = [".rst", ".md"]
6466
# source_suffix = '.rst'
6567

6668
# The master toctree document.
67-
master_doc = 'index'
69+
master_doc = "index"
6870

6971
# The language for content autogenerated by Sphinx. Refer to documentation
7072
# for a list of supported languages.
@@ -76,7 +78,7 @@
7678
# List of patterns, relative to source directory, that match files and
7779
# directories to ignore when looking for source files.
7880
# This pattern also affects html_static_path and html_extra_path.
79-
exclude_patterns = [u'_build', 'Thumbs.db', '.DS_Store']
81+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
8082

8183
# The name of the Pygments (syntax highlighting) style to use.
8284
pygments_style = None
@@ -90,21 +92,30 @@
9092
# The theme to use for HTML and HTML Help pages. See the documentation for
9193
# a list of builtin themes.
9294
#
93-
html_theme = 'sphinx_rtd_theme'
95+
html_theme = "sphinx_rtd_theme"
9496

9597
# Theme options are theme-specific and customize the look and feel of a theme
9698
# further. For a list of options available for each theme, see the
9799
# documentation.
98100
#
99-
html_theme_options = {
100-
'analytics_id': 'UA-83738774-2',
101-
'navigation_with_keys': True
102-
}
101+
html_theme_options = {"analytics_id": "UA-83738774-2", "navigation_with_keys": True}
102+
103+
# Configuration for OpenGraph and Twitter Card Tags.
104+
# These are responsible for creating nice shareable social images https://ahrefs.com/blog/open-graph-meta-tags/
105+
# https://ogp.me/#type_website
106+
ogp_image = "https://huggingface.co/front/thumbnails/transformers.png"
107+
ogp_description = "State-of-the-art Natural Language Processing for PyTorch and TensorFlow 2.0. Transformers provides thousands of pretrained models to perform tasks on texts such as classification, information extraction, question answering, summarization, translation, text generation, etc in 100+ languages. Its aim is to make cutting-edge NLP easier to use for everyone"
108+
ogp_description_length = 160
109+
110+
ogp_custom_meta_tags = [
111+
f'<meta name="twitter:image" content="{ogp_image}">',
112+
f'<meta name="twitter:description" content="{ogp_description}">',
113+
]
103114

104115
# Add any paths that contain custom static files (such as style sheets) here,
105116
# relative to this directory. They are copied after the builtin static files,
106117
# so a file named "default.css" will overwrite the builtin "default.css".
107-
html_static_path = ['_static']
118+
html_static_path = ["_static"]
108119

109120
# Custom sidebar templates, must be a dictionary that maps document names
110121
# to template names.
@@ -116,17 +127,17 @@
116127
#
117128
# html_sidebars = {}
118129

119-
# This must be the name of an image file (path relative to the configuration
120-
# directory) that is the favicon of the docs. Modern browsers use this as
121-
# the icon for tabs, windows and bookmarks. It should be a Windows-style
130+
# This must be the name of an image file (path relative to the configuration
131+
# directory) that is the favicon of the docs. Modern browsers use this as
132+
# the icon for tabs, windows and bookmarks. It should be a Windows-style
122133
# icon file (.ico).
123-
html_favicon = 'favicon.ico'
134+
html_favicon = "favicon.ico"
124135

125136

126137
# -- Options for HTMLHelp output ---------------------------------------------
127138

128139
# Output file base name for HTML help builder.
129-
htmlhelp_basename = 'transformersdoc'
140+
htmlhelp_basename = "transformersdoc"
130141

131142

132143
# -- Options for LaTeX output ------------------------------------------------
@@ -135,15 +146,12 @@
135146
# The paper size ('letterpaper' or 'a4paper').
136147
#
137148
# 'papersize': 'letterpaper',
138-
139149
# The font size ('10pt', '11pt' or '12pt').
140150
#
141151
# 'pointsize': '10pt',
142-
143152
# Additional stuff for the LaTeX preamble.
144153
#
145154
# 'preamble': '',
146-
147155
# Latex figure (float) alignment
148156
#
149157
# 'figure_align': 'htbp',
@@ -153,19 +161,15 @@
153161
# (source start file, target name, title,
154162
# author, documentclass [howto, manual, or own class]).
155163
latex_documents = [
156-
(master_doc, 'transformers.tex', u'transformers Documentation',
157-
u'huggingface', 'manual'),
164+
(master_doc, "transformers.tex", "transformers Documentation", "huggingface", "manual"),
158165
]
159166

160167

161168
# -- Options for manual page output ------------------------------------------
162169

163170
# One entry per manual page. List of tuples
164171
# (source start file, name, description, authors, manual section).
165-
man_pages = [
166-
(master_doc, 'transformers', u'transformers Documentation',
167-
[author], 1)
168-
]
172+
man_pages = [(master_doc, "transformers", "transformers Documentation", [author], 1)]
169173

170174

171175
# -- Options for Texinfo output ----------------------------------------------
@@ -174,9 +178,15 @@
174178
# (source start file, target name, title, author,
175179
# dir menu entry, description, category)
176180
texinfo_documents = [
177-
(master_doc, 'transformers', u'transformers Documentation',
178-
author, 'transformers', 'One line description of project.',
179-
'Miscellaneous'),
181+
(
182+
master_doc,
183+
"transformers",
184+
"transformers Documentation",
185+
author,
186+
"transformers",
187+
"One line description of project.",
188+
"Miscellaneous",
189+
),
180190
]
181191

182192

@@ -195,11 +205,13 @@
195205
# epub_uid = ''
196206

197207
# A list of files that should not be packed into the epub file.
198-
epub_exclude_files = ['search.html']
208+
epub_exclude_files = ["search.html"]
209+
199210

200211
def setup(app):
201-
app.add_css_file('css/huggingface.css')
202-
app.add_css_file('css/code-snippets.css')
203-
app.add_js_file('js/custom.js')
212+
app.add_css_file("css/huggingface.css")
213+
app.add_css_file("css/code-snippets.css")
214+
app.add_js_file("js/custom.js")
215+
204216

205217
# -- Extension configuration -------------------------------------------------

setup.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
"sphinx-copybutton",
127127
"sphinx-markdown-tables",
128128
"sphinx-rtd-theme==0.4.3", # sphinx-rtd-theme==0.5.0 introduced big changes in the style.
129+
"sphinxext-opengraph==0.4.1",
129130
"sphinx==3.2.1",
130131
"starlette",
131132
"tensorflow-cpu>=2.3",
@@ -243,11 +244,25 @@ def run(self):
243244
+ extras["modelcreation"]
244245
)
245246
extras["docs"] = deps_list(
246-
"docutils", "recommonmark", "sphinx", "sphinx-markdown-tables", "sphinx-rtd-theme", "sphinx-copybutton"
247+
"docutils",
248+
"recommonmark",
249+
"sphinx",
250+
"sphinx-markdown-tables",
251+
"sphinx-rtd-theme",
252+
"sphinx-copybutton",
253+
"sphinxext-opengraph",
247254
)
248255
extras["quality"] = deps_list("black", "isort", "flake8")
249256

250-
extras["all"] = extras["tf"] + extras["torch"] + extras["flax"] + extras["sentencepiece"] + extras["tokenizers"] + extras["speech"] + extras["vision"]
257+
extras["all"] = (
258+
extras["tf"]
259+
+ extras["torch"]
260+
+ extras["flax"]
261+
+ extras["sentencepiece"]
262+
+ extras["tokenizers"]
263+
+ extras["speech"]
264+
+ extras["vision"]
265+
)
251266

252267
extras["dev"] = (
253268
extras["all"]

0 commit comments

Comments
 (0)