File: html

package info (click to toggle)
libcpucycles 0~20240318-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 476 kB
  • sloc: ansic: 776; python: 337; sh: 51; makefile: 30
file content (69 lines) | stat: -rwxr-xr-x 1,735 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python3

import os
import datetime
import markdown

def load(fn):
  with open(fn) as f:
    return f.read()

style = load('autogen/html-style')
sitetitle = load('autogen/html-title')

files = []

with open('autogen/html-files') as f:
  for line in f:
    line = line.strip()
    line = line.split(':')
    if len(line) != 3: continue
    files += [line]

for md,html,pagetitle in files:
  fnmd = 'doc/%s.md' % md
  fnhtml = 'doc/html/%s.html' % html
  output = ''

  x = load(fnmd)
  x = markdown.markdown(x,extensions=['markdown.extensions.extra','markdown.extensions.tables'])
  mtime = datetime.datetime.utcfromtimestamp(os.path.getmtime(fnmd)).strftime('%Y.%m.%d')

  output += '<html>\n<head>\n'
  output += style
  output += '<title>\n'
  output += pagetitle
  output += '</title>\n'
  output += '</head>\n'
  output += '<body>\n'

  output += '<div class=headline>\n'
  output += sitetitle
  output += '</div>\n'

  output += '<div class=nav>\n'
  for submd,subhtml,subpagetitle in files:
    if subhtml == html:
      output += '<div class="navt here">'
      output += pagetitle+'\n'
    else:
      output += '<div class="navt away">'
      output += '<a href=%s.html>%s</a>\n' % (subhtml,subpagetitle)
    output += '</div>'
  output += '</div>\n'

  output += '<div class=main>\n'
  output += x
  output += '<hr><font size=1><b>Version:</b>\n'
  output += 'This is version %s of the "%s" web page.\n' % (mtime,pagetitle)
  output += '</font>\n'
  output += '</div>\n'

  output += '</body>\n'
  output += '</html>\n'

  if not os.path.exists(fnhtml) or output != load(fnhtml):
    with open(fnhtml+'.new','w') as f:
      f.write(output)
    os.chmod(fnhtml+'.new',0o444)
    os.rename(fnhtml+'.new',fnhtml)