echo $HOME
/home/lily2004
# 作業ディレクトリ作成
mkdir -p $HOME/src
cd $HOME/src
# MPFR, GMP, MPC のソースをダウンロードしてインストール
wget https://ftp.gnu.org/gnu/gmp/gmp-6.2.1.tar.xz
tar xf gmp-6.2.1.tar.xz
cd gmp-6.2.1
./configure --prefix=$HOME/local
make
make install
cd ..
wget https://www.mpfr.org/mpfr-4.2.1/mpfr-4.2.1.tar.xz
tar xf mpfr-4.2.1.tar.xz
cd mpfr-4.2.1
./configure --prefix=$HOME/local --with-gmp=$HOME/local
make
make install
cd ..
wget https://ftp.gnu.org/gnu/mpc/mpc-1.2.1.tar.gz
tar xf mpc-1.2.1.tar.gz
cd mpc-1.2.1
./configure --prefix=$HOME/local --with-gmp=$HOME/local --with-mpfr=$HOME/local
make
make install
cd ..
# GCCのダウンロード
wget https://ftp.gnu.org/gnu/gcc/gcc-11.4.0/gcc-11.4.0.tar.xz
tar xf gcc-11.4.0.tar.xz
cd gcc-11.4.0
# GCCのビルド準備
./configure --prefix=$HOME/local --with-gmp=$HOME/local --with-mpfr=$HOME/local --with-mpc=$HOME/local --enable-languages=c,c++ --disable-multilib
make
make install
cd ..
# Pythonのインストール準備
wget https://www.python.org/ftp/python/3.12.3/Python-3.12.3.tgz
tar xf Python-3.12.3.tgz
cd Python-3.12.3
# make_index.2.py
# -*- coding: utf-8 -*-
import os
import json
import sys
import chardet
from bs4 import BeautifulSoup
# ファイルのエンコーディングを判定する関数
def detect_encoding(file_path):
with open(file_path, 'rb') as f:
raw_data = f.read()
result = chardet.detect(raw_data)
return result['encoding'] or 'utf-8' # 結果がない場合はutf-8を返す
# HTMLから独自タイトルと本文を抽出する関数
def extract_custom_title_and_text(file_path):
encoding = detect_encoding(file_path) # エンコーディングを検出
with open(file_path, 'r', encoding=encoding, errors='ignore') as f:
html = f.read()
soup = BeautifulSoup(html, 'html.parser')
# 独自タイトル抽出
th_title = soup.find('th', class_='hpb-cnt-tb-th1')
title = ''
if th_title:
title = th_title.get_text(strip=True)
# 本文も抽出(検索用)
body = soup.get_text(separator=' ', strip=True)
return title, body
def main(folder, output_file):
index_data = []
for filename in os.listdir(folder):
# if filename.endswith('.html', '.php'):
if filename.endswith(('.html', '.php')):
full_path = os.path.join(folder, filename)
try:
title, content = extract_custom_title_and_text(full_path)
# ファイル名をリンクとして埋め込む
link = f'<a href="{filename}" target="B">{filename}</a>'
# データをindex_dataに追加
index_data.append({
'title': title or link,
'file': filename,
'link': link,
'content': content[:300]
})
except Exception as e:
print(f"Error processing {filename}: {e}")
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(index_data, f, ensure_ascii=False, indent=2)