mirror of
				https://github.com/em-squared/5e-drs.git
				synced 2025-10-31 05:24:20 +00:00 
			
		
		
		
	Draft.
This commit is contained in:
		
							parent
							
								
									c670e36803
								
							
						
					
					
						commit
						1aa2a16289
					
				
					 5 changed files with 82 additions and 0 deletions
				
			
		
							
								
								
									
										2
									
								
								contrib/meilisearch/.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								contrib/meilisearch/.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,2 @@ | ||||||
|  | venv | ||||||
|  | data.ms | ||||||
							
								
								
									
										12
									
								
								contrib/meilisearch/Makefile
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								contrib/meilisearch/Makefile
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,12 @@ | ||||||
|  | 
 | ||||||
|  | venv: | ||||||
|  | 	python3 -m venv venv | ||||||
|  | 	./venv/bin/pip install -U pip wheel | ||||||
|  | 	./venv/bin/pip install -r requirements.txt | ||||||
|  | 
 | ||||||
|  | up: | ||||||
|  | 	docker-compose up -d | ||||||
|  | 	docker ps | ||||||
|  | 
 | ||||||
|  | pull: | ||||||
|  | 	docker-compose pull | ||||||
							
								
								
									
										11
									
								
								contrib/meilisearch/docker-compose.yml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								contrib/meilisearch/docker-compose.yml
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,11 @@ | ||||||
|  | --- | ||||||
|  | 
 | ||||||
|  | version: "3" | ||||||
|  | 
 | ||||||
|  | services: | ||||||
|  |   meilisearch: | ||||||
|  |     image: getmeili/meilisearch:latest | ||||||
|  |     volumes: | ||||||
|  |      - ./data.ms:/data.ms | ||||||
|  |     ports: | ||||||
|  |      - 7700:7700 | ||||||
							
								
								
									
										54
									
								
								contrib/meilisearch/index.py
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										54
									
								
								contrib/meilisearch/index.py
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,54 @@ | ||||||
|  | #!/usr/bin/env python3 | ||||||
|  | 
 | ||||||
|  | from pathlib import Path | ||||||
|  | from io import StringIO | ||||||
|  | 
 | ||||||
|  | import yaml | ||||||
|  | from markdown import markdown | ||||||
|  | from meilisearch import Client | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def pages(): | ||||||
|  |     "return all pages" | ||||||
|  |     for readme in Path('.').glob('**/README.md'): | ||||||
|  |         if readme == Path("README.md"): # it's the home | ||||||
|  |             continue | ||||||
|  |         with open(readme, 'r') as file: | ||||||
|  |             head = StringIO() | ||||||
|  |             body = StringIO() | ||||||
|  |             state = None | ||||||
|  |             for line in file: | ||||||
|  |                 if state is None and line == "---\n": | ||||||
|  |                     state = "head" | ||||||
|  |                     continue | ||||||
|  |                 if state == "head": | ||||||
|  |                     if line == "---\n": | ||||||
|  |                         state = "body" | ||||||
|  |                         continue | ||||||
|  |                     head.write(line) | ||||||
|  |                 else: | ||||||
|  |                     body.write(line) | ||||||
|  |             if head.tell() == 0: # empty | ||||||
|  |                 continue | ||||||
|  |             head.seek(0) | ||||||
|  |             head = yaml.safe_load(head) | ||||||
|  |             body.seek(0) | ||||||
|  |             txt = markdown(body.read()) | ||||||
|  |             yield str(readme), head['title'], txt | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | if __name__ == "__main__": | ||||||
|  |     client = Client('http://127.0.0.1:7700') | ||||||
|  |     try: | ||||||
|  |         idx = client.get_index('pages') | ||||||
|  |     except Exception: | ||||||
|  |         client.create_index('pages', dict(primaryKey='path')) | ||||||
|  |     print(idx) | ||||||
|  |      | ||||||
|  |     for path, title, body in pages(): | ||||||
|  |         client.index('pages').add_documents([{ | ||||||
|  |             'path': path, | ||||||
|  |             'title': title, | ||||||
|  |             'body': body, | ||||||
|  |         }]) | ||||||
|  |         print(title) | ||||||
							
								
								
									
										3
									
								
								contrib/meilisearch/requirements.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								contrib/meilisearch/requirements.txt
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | ||||||
|  | pyyaml | ||||||
|  | meilisearch | ||||||
|  | markdown | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Mathieu Lecarme
						Mathieu Lecarme