Skip to content

Commit

Permalink
新增《遥感学报》样式(#369
Browse files Browse the repository at this point in the history
  • Loading branch information
zepinglee committed Sep 29, 2024
1 parent 1ddee58 commit 7f0f15d
Show file tree
Hide file tree
Showing 4 changed files with 1,333 additions and 0 deletions.
68 changes: 68 additions & 0 deletions scripts/make_new_style.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import argparse
from pathlib import Path
import re
import shutil


DEFAULT_BASE_STYLE = "gb-t-7714-2015-numeric-bilingual-no-uppercase-no-url-doi"


def main():
parser = argparse.ArgumentParser()
parser.add_argument("style")
parser.add_argument("base_style", nargs="?")
args = parser.parse_args()

style = args.style.lower().replace(" ", "-").replace("&", "and")

base_style = args.base_style or DEFAULT_BASE_STYLE
if base_style.startswith("src/"):
base_style = base_style.removeprefix("src/").removesuffix("/")

shutil.copytree(f"src/{base_style}", f"src/{style}")
shutil.move(f"src/{style}/{base_style}.csl", f"src/{style}/{style}.csl")
style_file = Path(f"src/{style}/{style}.csl")

style_content = style_file.read_text()

style_content = re.sub(
r"<title>.*?</title>", f"<title>{style}</title>", style_content
)
style_content = re.sub(
r"<id>.*?</id>",
f"<id>http://www.zotero.org/styles/{style}</id>",
style_content,
)
style_content = re.sub(
r'<link .*? rel="self"/>',
f'<link href="http://www.zotero.org/styles/{style}" rel="self"/>',
style_content,
)
if 'rel="template"' in style_content:
style_content = re.sub(
r'<link .*? rel="template"/>',
f'<link href="http://www.zotero.org/styles/{base_style}" rel="template"/>',
style_content,
)
else:
style_content = re.sub(
r'rel="self"/>',
f'rel="self"/>\n <link href="http://www.zotero.org/styles/{base_style}" rel="template"/>',
style_content,
)
if "<summary>" in style_content:
style_content = re.sub(
r"<summary>.*?</summary>", f"<summary>{style}</summary>", style_content
)
else:
style_content = re.sub(
r"<updated>",
f"<summary>{style}</summary>\n <updated>",
style_content,
)

style_file.write_text(style_content)


if __name__ == "__main__":
main()
Loading

0 comments on commit 7f0f15d

Please sign in to comment.