numpy / numpy.org

The NumPy home page
http://numpy.org/
BSD 3-Clause "New" or "Revised" License
111 stars 106 forks source link

Update theme (v0.15 and v0.14) #735

Closed jarrodmillman closed 6 months ago

jarrodmillman commented 6 months ago

@steppi @rgommers FYI, this updates the grid and figure shortcodes.

netlify[bot] commented 6 months ago

Deploy Preview for numpy-org ready!

Name Link
Latest commit 8226ea8c4f8fd15aa309b4ecbb41f27925431495
Latest deploy log https://app.netlify.com/sites/numpy-org/deploys/65fab37cb4717600083236d0
Deploy Preview https://deploy-preview-735--numpy-org.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

jarrodmillman commented 6 months ago

I used this script to convert between the format for Hugo's figure shortcode and the theme's figure shortcode:

import shlex
import sys

def replace_figure_shortcode(figure):
    figure = figure.replace('*', '')
    figure = figure.replace('align="middle"', 'align="center"')
    figure = figure.replace('caption=', 'title=')
    figure = figure.replace('attr=', 'attribution=')
    figure = figure.replace('attrlink=', 'attributionlink=')
    contents = figure[11:-4]
    parameters = shlex.split(contents)
    parameters = [s for s in parameters if not s.startswith("class=")]
    toml = [s.replace("=", " = '") + "'" for s in parameters]
    return "\n".join(["{{< figure >}}"] + toml + ["{{< /figure >}}\n"])

filename = sys.argv[1]
start = "{{< figure src="
end = ">}}\n"

with open(filename, "r") as f:
    lines = f.readlines()

with open(filename, "w") as f:
    for line in lines:
        if line.startswith(start) and line.endswith(end):
            line = replace_figure_shortcode(line)
        f.write(line)