从零开始学JPress主题制作——模板初始化

JPress之家发布 开发教程 2016-09-05 3653

近期很多朋友在群里问关于JPress主题制作的教程,JPress开发者海哥之前虽然发布过视频教程,但是竟然好多人不知道。。。

视频教程:百度云盘链接

这边小编就负责整理下如何初始化一个主题,作为制作主题的第一步,内容差不多都是来自视频。

1、复制自带主题JBlog,并且重命名为jpress-web-template-one(假设我们制作一个叫one的主题)

2、修改模板pom.xml文件,内容如下:

<?xml version="1.0"?>
<project
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>io.jpress</groupId>
		<artifactId>jpress</artifactId>
		<version>1.0</version>
	</parent>
	<artifactId>jpress-web-template-one</artifactId>
	<packaging>war</packaging>
	<name>jpress-web-template-one Template</name>
	<build>
		<finalName>template-one</finalName>
	</build>
</project>

 

3、删除原先

/jpress-web-template-one/src/main/webapp/templates/ 

下面的jblog文件夹,是的,全部删除!

 

4、在该目录

/jpress-web-template-one/src/main/webapp/templates/ 

下面创建one文件夹,即你马上制作的模板主文件夹,html模板什么的就放在这边了。

5、修改模板名称,在one文件夹下创建tpl_config.xml文件,内容如下

<?xml version="1.0" encoding="UTF-8"?>
<config>
	<infos>
		<title>One</title>
		<id>One</id>
		<description>One是JPress的模板</description>
		<author>jpress.cc</author>
		<authorWebsite>http://www.jpress.cc</authorWebsite>
		<version>v1.0</version>
		<versionCode>1</versionCode>
		<updateUrl>http://www.jpress.cc</updateUrl>
	</infos>

	<module title="文章" name="article" list="所有文章" add="撰写文章" comment="评论">
		<taxonomy title="分类" name="category" formType="select" />
		<taxonomy title="专题" name="feature" formType="select" >
			<metadata dataType="input" name="author" title="专题作者"  description="这个数据只是模板自定义模型的测试。" placeholder="请填写作者用户名"/>
		</taxonomy>
		<taxonomy title="标签" name="tag" formType="input" />
		
		<metadata dataType="input" name="_meta1" title="元数据1"  placeholder="元数据测试1"/>
		<metadata dataType="input" name="_meta2" title="元数据2"  placeholder="元数据测试2"/>
	</module>

	<module title="页面" name="page" list="所有页面" add="新建页面" comment="评论">
	</module>

	<thumbnail name="t1" size="780 x 240" />
	<thumbnail name="t2" size="240 x 140" />
	<thumbnail name="t3" size="600 x 300" />
	<thumbnail name="t4" size="300 x 300" />

</config>

6、修改模板预览文件,预览图片名称必须为:tpl_screenshot.png,替换成你制作模板的静态图片就可以了。到这里,模板制作初步完成。

7、接下来就是要让模板在后台显示出来,接下来就是maven的相关配置了。首先打开jpress-web模块中pom.xml文件,在dependencies标签下添加主题依赖

<dependency>
    <groupId>io.jpress</groupId>
    <artifactId>jpress-web-template-one</artifactId>
    <version>1.0</version>
    <type>war</type>
    <scope>compile</scope>
</dependency>

 

接着在overlays标签内添加主题:

<overlay>
    <groupId>io.jpress</groupId>
    <artifactId>jpress-web-template-one</artifactId>
</overlay>

如果你是新手,完全没有改动过jpress-web下面的pom.xml文件,那么改完之后文件应该是这样的:

<?xml version="1.0"?>
<project
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
	xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>io.jpress</groupId>
		<artifactId>jpress</artifactId>
		<version>1.0</version>
	</parent>
	<artifactId>jpress-web</artifactId>
	<name>jpress-web</name>
	<packaging>war</packaging>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>com.jfinal</groupId>
			<artifactId>cos</artifactId>
			<version>26Dec2008</version>
		</dependency>
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>druid</artifactId>
		</dependency>
		<dependency>
			<groupId>net.sf.ehcache</groupId>
			<artifactId>ehcache</artifactId>
		</dependency>
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
		</dependency>
		<dependency>
			<groupId>org.freemarker</groupId>
			<artifactId>freemarker</artifactId>
		</dependency>
		<dependency>
			<groupId>javax.mail</groupId>
			<artifactId>javax.mail-api</artifactId>
		</dependency>

		<dependency>
			<groupId>com.sun.mail</groupId>
			<artifactId>javax.mail</artifactId>
		</dependency>
		<dependency>
			<groupId>com.jfinal</groupId>
			<artifactId>jfinal</artifactId>
		</dependency>
		<dependency>
			<groupId>com.jfinal</groupId>
			<artifactId>jfinal-weixin</artifactId>
		</dependency>
		<dependency>
			<groupId>org.jsoup</groupId>
			<artifactId>jsoup</artifactId>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
		</dependency>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
		</dependency>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
		</dependency>

		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<scope>provided</scope>
		</dependency>

		<dependency>
			<groupId>io.jpress</groupId>
			<artifactId>jpress-utils</artifactId>
			<version>1.0</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>io.jpress</groupId>
			<artifactId>jpress-db-api</artifactId>
			<version>1.0</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>io.jpress</groupId>
			<artifactId>jpress-db-mysql</artifactId>
			<version>1.0</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>

		<dependency>
			<groupId>io.jpress</groupId>
			<artifactId>jpress-oauth2</artifactId>
			<version>1.0</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>

		<dependency>
			<groupId>io.jpress</groupId>
			<artifactId>jpress-message</artifactId>
			<version>1.0</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>

		<dependency>
			<groupId>io.jpress</groupId>
			<artifactId>jpress-search-api</artifactId>
			<version>1.0</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>


		<dependency>
			<groupId>io.jpress</groupId>
			<artifactId>jpress-search-dbsimple</artifactId>
			<version>1.0</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>

		<dependency>
			<groupId>io.jpress</groupId>
			<artifactId>jpress-consts</artifactId>
			<version>1.0</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>


		<dependency>
			<groupId>io.jpress</groupId>
			<artifactId>jpress-model</artifactId>
			<version>1.0</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>

		<dependency>
			<groupId>io.jpress</groupId>
			<artifactId>jpress-web-core</artifactId>
			<version>1.0</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>

		<dependency>
			<groupId>io.jpress</groupId>
			<artifactId>jpress-web-template-jblog</artifactId>
			<version>1.0</version>
			<type>war</type>
			<scope>compile</scope>
		</dependency>

		<dependency>
			<groupId>io.jpress</groupId>
			<artifactId>jpress-web-template-the3</artifactId>
			<version>1.0</version>
			<type>war</type>
			<scope>compile</scope>
		</dependency>
		
		<dependency>
			<groupId>io.jpress</groupId>
			<artifactId>jpress-web-template-one</artifactId>
			<version>1.0</version>
			<type>war</type>
			<scope>compile</scope>
		</dependency>

	</dependencies>

	<build>
		<finalName>${project.artifactId}-${project.version}</finalName>
		<resources>
			<resource>
				<directory>src/main/config</directory>
				<includes>
					<include>**/*.*</include>
				</includes>
				<filtering>false</filtering>
			</resource>
			<resource>
				<directory>src/main/language</directory>
				<includes>
					<include>**/*.*</include>
				</includes>
				<filtering>false</filtering>
			</resource>
		</resources>

		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>


			<plugin>
				<groupId>org.apache.tomcat.maven</groupId>
				<artifactId>tomcat6-maven-plugin</artifactId>
				<version>2.2</version>
			</plugin>

			<plugin>
				<groupId>org.apache.tomcat.maven</groupId>
				<artifactId>tomcat7-maven-plugin</artifactId>
				<version>2.2</version>
			</plugin>

			<plugin>
				<groupId>org.mortbay.jetty</groupId>
				<artifactId>maven-jetty-plugin</artifactId>
				<version>6.1.10</version>
			</plugin>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<configuration>
					<overlays>
						<overlay>
							<groupId>io.jpress</groupId>
							<artifactId>jpress-web-template-jblog</artifactId>
						</overlay>
						<overlay>
							<groupId>io.jpress</groupId>
							<artifactId>jpress-web-template-one</artifactId>
						</overlay>
						<overlay>
							<groupId>io.jpress</groupId>
							<artifactId>jpress-web-template-the3</artifactId>
						</overlay>
					</overlays>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

 

8、最后就是在jpress项目根目录的pom.xml文件中添加modules一来,添加一行即可:

 

<module>jpress-web-template-one</module>

这样基本就大功告成啦,现在主题就算搭好了,由于还没有模板文件,所以会显示空白,后台会提示很多404找不到文件,大家不用担心。 下一篇给大家如何利用jpress强大的标签展示数据。